- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我试图了解如何从 docopt.Parse() 输出访问多个输入参数。
示例:
package main
import (
"fmt"
"github.com/docopt/docopt-go"
)
func main() {
usage := `blah.go
Usage:
blah.go read <file> ...
blah.go -h | --help | --version`
arguments, _ := docopt.Parse(usage, nil, true, "blah 1.0", false)
x := arguments["<file>"]
fmt.Println(x)
fmt.Println(x)
}
命令行:
$ go run blah.go read file1 file2
[file1 file2]
[file1 file2]
我只想打印出 file1 或 file2。
当我尝试添加时:
fmt.Println(x[0])
我收到以下错误:
$ go run blah.go read file1 file2
# command-line-arguments
./blah.go:19: invalid operation: x[0] (index of type interface {})
最佳答案
根据文档 ( https://godoc.org/github.com/docopt/docopt.go#Parse ),返回类型是 map[string]interface{}
这意味着 arguments["<file>"]
给你一个 interface{}
类型的变量.这意味着您需要某种类型的转换才能使用它 ( http://golang.org/doc/effective_go.html#interface_conversions )。大概 x.([]string)
会成功的。
关于go - Docopt - Golang - 如何访问重复的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24047008/
我有一个小型 python 程序,需要在安装了核心 python (3.6....) 的系统上运行。我很想使用 docopt 来定义参数解析(和帮助文本),但我不希望能够依赖可用的 docopt 模块
为什么此代码会失败并出现以下异常? """my_program - for doing awesome stuff Usage: my_program [--foo] Options: --f
我在 docopt 中有以下用法: cli.py add_user [] cli.py remove_user (--id|--username) 在哪里[]是可选参数。 但是,当我尝试这
我希望我的脚本像“cp”命令那样接受命令行参数: ''' Usage: cp.py ... cp.py -t ... cp.py -s ... -t ''' 那些命令行 $ python cp.
我在用于 Docopt 配置的文档字符串中有一些详细的选项规范。有些条目相当长。有没有办法对文本进行换行以使其更清晰或更容易适应线宽? 假设文档字符串中的相关文本如下: Usage: prog
我通常在 Python 中使用 argparse,在 R 中使用 docopt。我错过了 argparse 中我尚未在 docopt 中弄清楚的功能之一,即能够为每个参数指定所需的数据类型。例如,在
我想使用 docopt 来解析可以多次接收相同选项的命令行。有人可以解释一下该怎么做吗? 一个测试例子: #!/usr/bin/env python """ Test program. Usage:
是否有更好的方法来处理此验证: #!/usr/bin/env python """ command. Usage: command start ID command finish ID FIL
我正在使用 docopt 在我的简单 Python 程序中: #!/usr/bin/env python """ Farmers market Usage: farmersmarket.py bu
我在让 docopt 将包含空格的参数解析为适当的字典对象以用于我的单元测试时遇到问题。 这是我目前用来构造 docopt 解析的参数列表的代码: testargs = [] def clear_ar
我正在使用docopt library . 我找不到完成以下要求的方法: 文档字符串是: """ aTXT tool Usage: aTXT ... [--ext ...] Options:
我正在尝试学习 python docopt 模块并拥有以下简单脚本: """ Usage: rsnapshot-once [-c CFGFILE] (sync|hourly|daily|monthly
我想要一个带有两个参数的选项。 IE。希望能够使用 $ ./foo --path "old" "new" 或者我真正想要的是: $ ./foo --path "old" "new" --path "o
查看 docopt 文档和示例,我似乎找不到此功能,但我觉得它应该存在,所以我想我会要求确认一下。 我正在使用 Python 的 docopt 并希望能够允许任意选项。该用例是一个命令行模板实用程序
使用 docopt 库查看这段代码: const USAGE: &'static str = "...something..."; #[derive(Deserialize)] struct Args
使用 docopt,有没有办法制作一个双虚线参数,可以使用和不使用等号? 我希望以下两个命令都使 --tls 为真: cmd --tls cmd --tls=true 我似乎只能通过使用让一个或另一个
我正在使用 docopt 来解析 python 中的命令行输入。我有我的文档字符串: """ Usage: docoptTest.py [options] Options: -h --help
我正在尝试使用 docopt 创建命令行界面。这是我的文件的简化版本: #!/usr/bin/env python """ Test program. Usage: test.py [option
我想使用 docopt 向我的程序传递两个强制参数和一个可选参数。我使用的代码是: """Setup Usage: myprog.py server_name config [--help] [opt
所以,我尝试从 docopt examples git repo 运行 odd_even_example.py . 无论我尝试做什么或更改,该示例都不会按预期工作。 当我: python odd_ev
我是一名优秀的程序员,十分优秀!