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

[cli] HelpFormatter doesn't function correctly for options with only LongOpt

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • 1.1
    • CLI-1.x
    • None
    • Operating System: All
      Platform: All

    • 33340

    Description

      The following doesn't work (org.apache.commons.cli.HelpFormatter
      )correctly and doesn't print out the help menu of options
      that only specify LongOpt.

      The output is:
      [java] usage: -a | -d | --shutdown | -s | -h [-r <email>] [-f <flight>] [-t]
      [java] VendMore - Email Management System
      [java] t,-test test mode - makes no permanent changes.
      [java] --shutdown shutdown rpc server.
      [java] a,-add add user to email queue.
      [java] d,-delete delete user from email queue.
      [java] f,-flight flight which is the index into the email being sent
      [java] h,-help Print this usage information.
      [java] -r recipient's email
      [java] s,-send send email command
      [java] For more information, see Steve Morin
      [java] Java Result: 1

      it is missing the following options when printing the help display.

      options.addOption(OptionBuilder.withDescription("hostname for the XmlRpc
      client to connect to.").withLongOpt("hostname").create());
      options.addOption(OptionBuilder.withDescription("port for the xmlrpc
      client to use.").withLongOpt("port").create());
      options.addOption(OptionBuilder.withDescription("additional xmlrpc
      connection").withLongOpt("urlpath").create());
      options.addOption(OptionBuilder.withDescription("add a parameter
      form name=value.").hasArg().withLongOpt("params").create());

      example of the offending code

      private CommandLineParser cmd;
      private Options options;
      private OptionGroup ogmain;

      public CmdLineArg()

      { super(); cmd = new BasicParser(); options = new Options(); ogmain = new OptionGroup(); ogmain.setRequired(true); localinit(); init(); }

      public CommandLine run(String[] args) {

      try

      { options.addOption(OptionBuilder.withDescription("add a parameter form name=value.").hasArg().withLongOpt("params").create()); options.addOption(OptionBuilder.withDescription("recipient's email").hasArg().create('r')); options.addOption(OptionBuilder.withDescription("flight which is the index into the email being sent").withLongOpt("flight").hasArg().create('f')); options.addOption(OptionBuilder.withDescription("test mode - makes no permanent changes.").withLongOpt("test").create('t')); ogmain.addOption(OptionBuilder.withDescription("Print this usage information.").withLongOpt("help").create('h')); ogmain.addOption(OptionBuilder.withDescription("send email command").withLongOpt("send").hasArg().create('s')); ogmain.addOption(OptionBuilder.withDescription("add user to email queue.").withLongOpt("add").create('a')); ogmain.addOption(OptionBuilder.withDescription("delete user from email queue.").withLongOpt("delete").create('d')); ogmain.addOption(OptionBuilder.withDescription("shutdown rpc server.").withLongOpt("shutdown").create()); options.addOption(OptionBuilder.withDescription("hostname for the XmlRpc client to connect to.").withLongOpt("hostname").create()); options.addOption(OptionBuilder.withDescription("port for the xmlrpc client to use.").withLongOpt("port").create()); options.addOption(OptionBuilder.withDescription("additional xmlrpc connection").withLongOpt("urlpath").create()); options.addOptionGroup(this.ogmain); return cmd.parse(options,args); }

      catch (ParseException e)

      { printUsage(); System.exit(1); return null; }

      }

      protected void printUsage()

      { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(getUSAGE(),getHEADER(),options,getFOOTER()); }

      Attachments

        Activity

          People

            Unassigned Unassigned
            scruffy323@aol.com steve
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: