8 groovy
是否有针对Groovy的标准或推荐的getopts库,这将允许我在Groovy中快速处理长短命令行争论?
groovy foo.groovy --fname = foo.txt --output = foo.html --verbose
Chr*_*iak 15
您也可以简单地使用Groovy CliBuilder(内部使用Apache Commons Cli).
你会在这里找到一个很好的例子:> http://www.reverttoconsole.com/blog/codesnippets/groovy-clibuilder-in-practice/
def cli = new CliBuilder()
cli.with {
usage: 'Self'
h longOpt:'help', 'usage information'
i longOpt:'input', 'input file', args:1
o longOpt:'output', 'output file',args:1
a longOpt:'action', 'action to invoke',args:1
d longOpt:'directory','process all files of directory', args:1
}
def opt = cli.parse(args)
def action
if( args.length == 0) {
cli.usage()
return
}
if( opt.h ) {
cli.usage()
return
}
if( opt.i ) {
input = opt.i
}
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2983 次 |
| 最近记录: |