jtp*_*yda 8 format standards command-line command-line-arguments
命令行参数的典型格式是:
myApp --myArg=myValue
Run Code Online (Sandbox Code Playgroud)
如果我想通过命令行传递一组键值对怎么办?就像是:
myApp --myList={arg1=val1;arg2=val2;arg3=val3...}
Run Code Online (Sandbox Code Playgroud)
由于似乎没有这种事情的标准,任何人都可以提供具有这种命令行参数输入的常用实用程序的示例吗?我戳了一些手册,但没找到.
编辑:我想知道输入应该如何格式化以及帮助文本可能是什么样子.
我认为这在很大程度上取决于你如何解析程序中的参数.
以下是程序接受多个键值对值的一些示例.
男人php:
--define foo[=bar]
-d foo[=bar] Define INI entry foo with value bar
Run Code Online (Sandbox Code Playgroud)
男人git:
-c <name>=<value>
Pass a configuration parameter to the command. The value given will
override values from configuration files. The <name> is expected in
the same format as listed by git config (subkeys separated by
dots).
Run Code Online (Sandbox Code Playgroud)
对于两者,可以将多个-d
或-c
参数传递给程序,这使您能够向程序提供键值对列表.
IMO,只要它有效并且有详细记录,拥有自己接受程序键值对列表的风格并不是一个大问题.:)
PS:我认为这个问题更适合放在程序员堆栈交换而不是SO上.看到这里和这里.
如果应用程序需要这么多参数,我会使用配置文件而不是在命令行中传递它们:
myApp --config=file.cnf
这种方法有以下优点: