commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 13937] New: - Request that Options support hierarical options
Date Thu, 24 Oct 2002 15:56:32 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13937>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13937

Request that Options support hierarical options

           Summary: Request that Options support hierarical options
           Product: Commons
           Version: Nightly Builds
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: CLI
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: me@joemcglynn.com


It would be very useful if one could specify a hierarchy of options, for instance:

if I use -t as a switch:
   -x is allowed
   -y VALUE is required
if I use -u as a switch:
   -a is allowed
   -b allowed
   -c VALUE is allowed

>From a developer's perspective this might look like the following:

        cmdLineOpts = new Options();
        Option optionT        = new Option(OPTION_T,
                                           OPTION_T_LONG,
                                           false,
                                           OPTION_T_HELP);
        Option optionX        = new Option(OPTION_X,
                                           OPTION_X_LONG,
                                           false,
                                           OPTION_X_HELP);
        Option optionY        = new Option(OPTION_Y,
                                           OPTION_Y_LONG,
                                           true,
                                           OPTION_Y_HELP);
        optionY.setRequired();
        Option optionU        = new Option(OPTION_U,
                                           OPTION_U_LONG,
                                           false,
                                           OPTION_U_HELP);
        Option optionA        = new Option(OPTION_A,
                                           OPTION_A_LONG,
                                           false,
                                           OPTION_A_HELP);
        Option optionB        = new Option(OPTION_B,
                                           OPTION_B_LONG,
                                           false,
                                           OPTION_B_HELP);
        Option optionC        = new Option(OPTION_C,
                                           OPTION_C_LONG,
                                           true,
                                           OPTION_C_HELP);
        
        // set up optionT
        optionT.addChildOption(optionX);
        optionT.addChildOption(optionY);
        
        // set up optionU
        optionU.addChildOption(optionA);
        optionU.addChildOption(optionB);
        optionU.addChildOption(optionC);
        
        // build options for parsing cmd line
        cmdLineOpts.addOption(optionT);
        cmdLineOpts.addOption(optionU);


   



        // create discrete options, these are the main choices
        // for this program, exactly _ONE_ of these must be specified
        cmdLineOpts = new Options();
        OptionGroup mainOptions = new OptionGroup();
        Option generateAll =    new Option(OPTION_ALL,
                                           OPTION_ALL_LONG,
                                           false,
                                           OPTION_ALL_HELP);
        Option generateTarget = new Option(OPTION_TARGET,
                                           OPTION_TARGET_LONG,
                                           true,
                                           OPTION_TARGET_HELP);
        Option generateLocal =  new Option(OPTION_LOCALHOST,
                                           OPTION_LOCALHOST_LONG,
                                           false,
                                           OPTION_LOCALHOST_HELP);
        Option showHelp =       new Option(OPTION_HELP,
                                           OPTION_HELP_LONG,
                                           false,
                                           OPTION_HELP_HELP);
        // set up a group of mutually-exclusive command line options
        mainOptions.addOption(generateAll);
        mainOptions.addOption(generateTarget);
        mainOptions.addOption(generateLocal);
        mainOptions.addOption(showHelp);

        // The following is the enhancement
        mainOptions.setRequired();

        // build options for parsing cmd line
        cmdLineOpts.addOptionGroup(mainOptions);
        // etc...

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message