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

HelpFormatter missing <arg> for first option

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3
    • Component/s: CLI-1.x
    • Labels:
      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: