The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool.
The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool.
Commons CLI supports different types of options:
- POSIX like options (ie. tar -zxvf foo.tar.gz)
- GNU like long options (ie. du --human-readable --max-depth=1)
- Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
- Short options with value attached (ie. gcc -O2 foo.c)
- long options with single hyphen (ie. ant -projecthelp)
A typical help message displayed by Commons CLI looks like this:
usage: ls
-A,--almost-all do not list implied . and ..
-a,--all do not hide entries starting with .
-B,--ignore-backups do not list implied entries ending with ~
-b,--escape print octal escapes for nongraphic characters
--block-size <SIZE> use SIZE-byte blocks
-c with -lt: sort by, and show, ctime (time of last
modification of file status information) with
-l:show ctime and sort by name otherwise: sort
by ctime
-C list entries by columns