Skip to main content
added 470 characters in body
Source Link

You could use the refcodes-console artifact (see refcodes-console at Bitbucket)refcodes-console on REFCODES.ORG:

In the above example all defined arguments must be passed by the user, else the parser will detect a wrong usage. In case the --test switch is to be optionaloptional (or any other argument), assign theRoot as follows:

You could use the refcodes-console artifact (see refcodes-console at Bitbucket):

In case the --test switch is to be optional, assign theRoot as follows:

You could use the refcodes-console artifact at refcodes-console on REFCODES.ORG:

In the above example all defined arguments must be passed by the user, else the parser will detect a wrong usage. In case the --test switch is to be optional (or any other argument), assign theRoot as follows:

added 470 characters in body
Source Link

Evaluate the parsed arguments as follows: r.getValue() ); or if (test.getValue() == true) ...:

LOGGER.info( "r :=" + r.getValue() ); LOGGER.info( "S :=" + s.getValue() ); LOGGER.info( "arg1 :=" + arg1.getValue() ); LOGGER.info( "arg2 :=" + arg2.getValue() ); LOGGER.info( "arg3 :=" + arg3.getValue() ); LOGGER.info( "arg4 :=" + arg4.getValue() ); LOGGER.info( "test :=" + test.getValue() + "" ); LOGGER.info( "A :=" + a.getValue() ); 

Evaluate the parsed arguments as follows: r.getValue() ); or if (test.getValue() == true) ...:

LOGGER.info( "r :=" + r.getValue() ); LOGGER.info( "S :=" + s.getValue() ); LOGGER.info( "arg1 :=" + arg1.getValue() ); LOGGER.info( "arg2 :=" + arg2.getValue() ); LOGGER.info( "arg3 :=" + arg3.getValue() ); LOGGER.info( "arg4 :=" + arg4.getValue() ); LOGGER.info( "test :=" + test.getValue() + "" ); LOGGER.info( "A :=" + a.getValue() ); 
Source Link

You could use the refcodes-console artifact (see refcodes-console at Bitbucket):

Option<String> r = new StringOptionImpl( "-r", null, "opt1", "..." ); Option<String> s = new StringOptionImpl( "-S", null, "opt2", "..." ); Operand<String> arg1 = new StringOperandImpl( "arg1", "..." ); Operand<String> arg2 = new StringOperandImpl( "arg2", "..." ); Operand<String> arg3 = new StringOperandImpl( "arg3", "..." ); Operand<String> arg4 = new StringOperandImpl( "arg4", "..." ); Switch test = new SwitchImpl( null, "--test", "..." ); Option<String> a = new StringOptionImpl( "-A", null, "opt3", "..." ); Condition theRoot = new AndConditionImpl( r, s, a, arg1, arg2, arg3, arg4, test ); 

Create your arguments parser ArgsParserImpl with your root condition:

ArgsParser theArgsParser = new ArgsParserImpl( theRoot ); theArgsParser.setName( "MyProgramm" ); theArgsParser.setSyntaxNotation( SyntaxNotation.GNU_POSIX ); 

Above you define your syntax, below you invoke the parser:

theArgsParser.printUsage(); theArgsParser.printSeparatorLn(); theArgsParser.printOptions(); theArgsParser.evalArgs( new String[] { "-r", "RRRRR", "-S", "SSSSS", "11111", "22222", "33333", "44444", "--test", "-A", "AAAAA" } ); 

In case you provided some good descriptions, theArgsParser.printUsage() will even show you the pretty printed usage:

Usage: MyProgramm -r <opt1> -S <opt2> -A <opt3> arg1 arg2 arg3 arg4 --test 

In case the --test switch is to be optional, assign theRoot as follows:

theRoot = new AndConditionImpl( r, s, a, arg1, arg2, arg3, arg4, new OptionalImpl( test ) );

Then your syntax looks as follows:

Usage: MyProgramm -r <opt1> -S <opt2> -A <opt3> arg1 arg2 arg3 arg4 [--test] 

The full example for your case you find in the StackOverFlowExamle. You can use AND, OR, XOR conditions and any kind of nesting ... hope this helps.