You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2006/07/10 07:39:33 UTC

[jira] Updated: (CLI-33) stopAtNonOption not working for GnuParser

     [ http://issues.apache.org/jira/browse/CLI-33?page=all ]

Henri Yandell updated CLI-33:
-----------------------------

    Version:     (was: 1.0 Beta 2)

> stopAtNonOption not working for GnuParser
> -----------------------------------------
>
>          Key: CLI-33
>          URL: http://issues.apache.org/jira/browse/CLI-33
>      Project: Commons CLI
>         Type: Bug

>  Environment: Operating System: other
> Platform: Other
>     Reporter: John Keyes

>
> Submitted by Parag Thakur (parag at veritas.com):
> Here are the arguments i expect:
> cmd -exec -exec_opt1 -exec_opt2
> cmd -rep -rep_opt1 -rep_opt2
> Thus, depending on the first argument (-exec or -rep), i would like to parse
> the remaining arguments. So, here is the code snippet that i have:
>     // create the main options object which will handle the first parameter
>     Options mainOptions = new Options();
>     // There can be 2 main exclusive options:  -exec|-rep
>     // Therefore, place them in an option group
>     OptionGroup grp = new OptionGroup();
>     grp.addOption(new Option("exec",false,"description for this option"));
>     grp.addOption(new Option("rep",false,"description for this option"));
>     mainOptions.addOptionGroup(grp);
>     // for the exec option, there are 2 options...
>     execOptions = new Options();
>     execOptions.addOption("exec_opt1",false," desc");
>     execOptions.addOption("exec_opt2",false," desc");
>     // similarly, for rep there are 2 options...
>     repOptions = new Options();
>     repOptions.addOption("rep_opt1","false","desc");
>     repOptions.addOption("rep_opt2","false","desc");
>     // create the parser
>     CommandLineParser parser =
> CommandLineParserFactory.newParser("org.apache.commons.cli.GnuParser");
>     // finally, parse the arguments:
>     // first parse the main options to see what the user has specified
>     // We set stopAtNonOption to true so it does not touch the remaining
>     // options
>     CommandLine cmd = parser.parse(mainOptions,argv,true);
>     // get the remaining options...
>     argv = cmd.getArgs();
>     if(cmd.hasOption("exec")){
>         cmd = parser.parse(execOptions,argv,false);
>         // process the exec_op1 and exec_opt2...
>     }
>     else if(cmd.hasOption("rep")){
>         cmd = parser.parse(repOptions,argv,false);
>         // process the rep_op1 and rep_opt2...
>     }
>     else {
>         printUsage();
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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