Friday, 16 December 2016

Apache Commons CLI Tutorial

CLI stands for command Line Interface. Commons CLI support different kinds of options.

a.   POSIX like options (ie. tar -zxvf foo.tar.gz)
b.   GNU like long options (ie. du --human-readable --max-depth=1)
c.    Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
d.   Short options with value attached (ie. gcc -O2 foo.c)
e.   long options with single hyphen (ie. ant -projecthelp)

By using Commons CLI library, you can generate help for any command line tool, parse the command line arguments, query the command line arguments.

Typical CLI output looks like below.

usage: FileCopy -i <FILE PATH> -o <FILE PATH> [-help] [-version] [-quiet] [-verbose] [-debug] [-lang
       <LANGUAGE>]
     -i,--input <FILE PATH>          input file to read data from
     -o,--output <FILE PATH>         output file to write the final result
     -help                           print this message
     -version                        print the version information and exit
     -quiet                          be extra quiet
     -verbose                        be extra verbose
     -debug                          print debugging information
     -lang,--language <LANGUAGE>     Encoding Langauge


Previous                                                 Next                                                 Home

No comments:

Post a Comment