Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
Commons CLI API - Long Options
How to manage long options with Apache Commons CLI API?
✍: FYIcenter.com
A long option is a long keyword (multiple characters) option prefixed with "--".
For example, "--help" is a long option. 
A long option is supported in Apache Commons CLI API as an alias of a short option. For example, "--help" is an alias of "-h".
A long 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 long the addOption() method with 4 arguments. For example:
import org.apache.commons.cli.Options;
      Options options = new Options();
      options.addOption("h", "help", false, "Print this help message");
2. Parse Options - A long 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 long option can be processed by calling the CommandLine.hasOption() method. For example:
         if (cmd.hasOption("help")) {
            help(options);
         }
4. Print Options - A long 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("LongOptionTest", options);
⇒ Commons CLI API - Long Options Example
⇐ Commons CLI API - Short Options Example
2020-12-22, ∼1133🔥, 0💬
Popular Posts:
What Is mail.jar of JavaMail 1.3? I got the JAR file from javamail-1_3.zip. mail.jar in javamail-1_3...
ANTLR is a powerful parser generator for multiple programming languages including Java. ANTLR contai...
JDK 11 jdk.crypto.ec.jmod is the JMOD file for JDK 11 Crypto EC module. JDK 11 Crypto EC module comp...
What Is jms.jar? I heard it's related to JMS (Java Message Service) 1.1? The if you have an jms.jar ...
How to download and install ojdbc14.jar for Oracle 10g R2? ojdbc14.jar for Oracle 10g R2 is a Java 1...