我试图了解如何从 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 {})