源码分析之Docopt-go
地址:https://github.com/docopt/docopt.go
Doc命令行解析工具
https://github.com/docopt/docopt.go
例子:
./flowanalysis checkcfg --config config/flowanalysis.test.toml go run
main.go checkcfg --config config/flowanalysis.test.toml
Format
var usage string = `
analysis
Usage:
analysis server --config=<file> [--consul]
analysis file --config=<file> --input=<file> [--output=<file>] [--output-agg=<file>]
analysis checkcfg --config=<file>
analysis dumpStorage --dir=<dir>
analysis collect --config=<file>
analysis query --from=<Now-1m> --to=<Now> [--address=<127.0.0.1:10130>]
analysis -h | --help
analysis -v | --version
Options:
-h --help Show this screen.
--version Show version.
--consul Register consul service
`
Docopt核心解析部分
//parse and return a map of args, output and all errors
func parse(doc string, argv []string, help bool, version string, optionsFirst bool) (args map[string]interface{}, output string, err error)
Docopt解析结果数据结构
arguments struct:
file => false
collect => false
--to => <nil>
--output-agg => <nil>
--from => <nil>
--address => <nil>
--help => false
--consul => false
--input => <nil>
--output => <nil>
dumpStorage => false
query => false
-v => false
--dir => <nil>
--version => false
server => false
--config => config/flowanalysis.test.toml
checkcfg => true
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。