groovy Clibuilder用法打印null

时间:2013-01-28 19:38:30

标签: groovy

更多的审美问题,但为什么打印cli.usage()最后会给出一个空值?

def cli = new CliBuilder(usage:'helloWord') 
 cli.help('prints this message') 
 cli.project(args:1, argName:'project', 'project name') 
 cli.desc(args:2, argName:'desc', 'project description')
 cli.f('force creation')
 def options = cli.parse(args)

if (options.help){
 print cli.usage()
 return
}

输出groovy helloWorld.groovy -help

 usage: helloWorld 
     -desc <desc>          project description
     -f                           force creation
     -help                        prints this message
     -project <project>           project name
    null

1 个答案:

答案 0 :(得分:3)

cli.usage()没有返回使用字符串;它打印用法字符串。而不是

print cli.usage()

只需在没有print的情况下调用它:

cli.usage()