Categories:
Audio (13)
Biotech (29)
Bytecode (35)
Database (77)
Framework (7)
Game (7)
General (512)
Graphics (53)
I/O (32)
IDE (2)
JAR Tools (86)
JavaBeans (16)
JDBC (89)
JDK (337)
JSP (20)
Logging (103)
Mail (54)
Messaging (8)
Network (71)
PDF (94)
Report (7)
Scripting (83)
Security (32)
Server (119)
Servlet (17)
SOAP (24)
Testing (50)
Web (19)
XML (301)
Other Resources:
Commons CLI API - Short Options
How to manage short options with Apache Commons CLI API?
✍: FYIcenter.com
A short option is a single character option prefixed with "-".
For example, "-h" is a short option.
A short option can be managed with Apache Commons CLI API in 4 steps:
1. Define Options - A short option can be defined and added to the options collection by calling the addOption() method with 2 arguments. For example:
import org.apache.commons.cli.Options; Options options = new Options(); options.addOption("h", "Print this help message");
2. Parse Options - A short option can be parsed together with all other options in a single call of CommandLineParser.parse(). For example:
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse( options, args);
3. Process Options - A short option can be processed by calling the CommandLine.hasOption() method. For example:
if (cmd.hasOption("h")) { help(options); }
4. Print Options - A short optoin can be printed out as help message together with all other options. For example:
import org.apache.commons.cli.HelpFormatter; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ShortOptionTest", options);
Â
⇒ Commons CLI API - Short Options Example
⇠Using commons-cli.jar in Java Programs
2020-12-22, 498👍, 0💬
Popular Posts:
Commons Pool provides an Object-pooling API, with three major aspects: 1. A generic object pool inte...
What is the sax\Counter.java provided in the Apache Xerces package? I have Apache Xerces 2.11.0 inst...
What Is commons-io-2.6.jar? commons-io-2.6.jar is the JAR file for Commons IO 2.5, which is a librar...
JDK 11 jdk.compiler.jmod is the JMOD file for JDK 11 Compiler tool, which can be invoked by the "jav...
What Is log4j-1.2.13.jar? I got the JAR file from logging-log4j-1.2.13.zip .log4j-1.2.13.jar is the ...