Jabda
Jabda

Reputation: 1792

groovy Clibuilder usage prints null

More of an aesthetic question, but why does printing cli.usage() give a null at the end?

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
}

output with groovy helloWorld.groovy -help

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

Upvotes: 1

Views: 371

Answers (1)

ataylor
ataylor

Reputation: 66069

cli.usage() doesn't return a usage string; it prints the usage string. Instead of

print cli.usage()

just call it without print:

cli.usage()

Upvotes: 3

Related Questions