源码分析之Docopt-go

源码分析之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
上一篇:数据岗位现状调查报告


下一篇:64个数据分析常用语