Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-233

HelpFormatter missing <arg> for first option

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 1.2
    • 1.3
    • CLI-1.x
    • None

    Description

      I'm not sure if this is fixed in the master branch, but it looks like the HelpFormatter doesn't correctly output a <arg> when the first option has an argument. Sample:

      Main.java
          Options options = new Options();
          options.addOption(OptionBuilder.withLongOpt("user").withDescription("Database username").isRequired().hasArg().create("u"));
          options.addOption(OptionBuilder.withLongOpt("pass").withDescription("Database password").isRequired().hasArg().create("p"));
      
          CommandLineParser parser = new PosixParser();
          CommandLine commandLine;
          try {
            commandLine = parser.parse(options, args);
          } catch (ParseException e) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp(120, "Usage: Main <options>", e.getMessage(), options, "");
            System.exit(1);
          }
      

      The output is:

      usage: Usage: Main <options>
      Missing required option: u, p
       -p,--pass <arg>    Database password
       -u,--user          Database username
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bpontarelli Brian Pontarelli
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: