Apache Commons CLI: how to prevent the use of short names for parameters?

In the Apache Commons CLI lib, is it possible to circumvent the use of a short name by forcing the user to use a long name?

Typically, parameters are defined as follows:

new Option("u", "username", true, "automatic user name") 

I would like to prohibit the use of "u". But if I replaced it with null or an empty string, there are Exceptions ...

Why is this a requirement? I would like all my options to be in the form --optionName = optionValue only, because some parts of my application: Spring Boot and Spring Boot recognize the default options in this format.

In addition, to ensure consistency between developers and users and to simplify the documentation, I think this is better if we have a unique way of using the option instead of 2.

+5
source share
1 answer

Going to null , since the short name works for me when using the latest version of Apache Commons Cli 1.3.1 and DefaultParser (which is the only one not outdated now):

  Options options = new Options(); Option option = new Option(null, "help", true, "some desc"); options.addOption(option); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse( options, new String[] {"--help=foobar"}); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "ant", options ); assertEquals(cmd.hasOption("help"), true); String optionValue = cmd.getOptionValue("help"); assertEquals("foobar", optionValue); 
+5
source

All Articles