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

check if all options are provided using CommandLine

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Validation
    • None

    Description

      I want to ad check if Options which marked as Required are available or not 

      My use case is to have a method like below in CommandLine class

      boolean hasAllRequiredOptions()

       Check below given expected code, (code kept uncompiled purposefully)

      import org.apache.commons.cli.*;
      
      public class CLITester {
          public static void main(String[] args) throws ParseException {
      
              Options options = new Options();
              options.addRequiredOption("p", "print", false, "Send print request to printer.")
                      .addRequiredOption("g", "gui", false, "Show GUI Application")
                      .addOption("n", "nothing", true, "No. of copies to print");
      
              CommandLineParser parser = new DefaultParser();
              CommandLine cmd = parser.parse(options, args);
              if (!cmd.hasAllRequiredOptions()) { // I want to have method like this which will check if all required options are available
      
                  HelpFormatter formatter = new HelpFormatter();
                  formatter.printHelp("CLITester", options);
              }
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mahadevkv Mahadev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: