源码分析之Docopt-go

2021/5/1 20:28:23

本文主要是介绍源码分析之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


这篇关于源码分析之Docopt-go的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程