public class GetOpt extends Object
-a) and long ( --freakin-long-option) options.-abqv), and if any options take parameters,
those will be read in sequence from the command line following the glommage.--) is recognized and handled.System.err.add...()processParams()get...Value()
com.bluecirclesoft.open.getopt.GetOpt.CommandLineOptionException:
error: Unknown option: -?
error: required option --output-dir was not given
usage:
com.bluecirclesoft.open.getopt.ClassGenerator.Output.JavaNoMiddle -d <directory> [
-D <type> ]
where:
-d, --output-dir <directory>:
(required) output the new classes/hierarchy to <directory>
-D, --date-type <type>:
the type to use for dates (default: javax.sql.Date)
at com.bluecirclesoft.open.getopt.GetOpt.GetOpt.processParams(GetOpt.java:459)
at com.bluecirclesoft.open.getopt.ClassGenerator.Output.JavaNoMiddle.setParams(JavaNoMiddle.java:80)
at com.bluecirclesoft.open.getopt.ClassGenerator.Generate.main(Generate.java:72)
And the code that generated it:
GetOpt opts = new GetOpt(getClass().getName());
opts.addParam('d', "output-dir", "directory",
"output the new classes/hierarchy to <directory>", true);
opts.addParam('D', "date-type", "type", "the type to use for dates
(default: "
+ m_DateType + ")", false);
opts.processParams(Options);
| Modifier and Type | Field and Description |
|---|---|
static CommandLineProcessingFlavors |
DEFAULT_FLAVOR |
| Modifier and Type | Method and Description |
|---|---|
OptionSpecification |
addFlag(String documentation,
Consumer<Boolean> onEncounter)
Add an option without an argument (a flag - true or false)
|
<T> void |
addLongOpt(OptionSpecification optionSpecification,
String opt) |
<T> OptionSpecification |
addParam(String paramMnemonic,
String documentation,
boolean required,
Class<T> type,
Consumer<T> onEncounter)
Add an option with argument (with a value to be passed in).
|
OptionSpecification |
addParam(String paramMnemonic,
String documentation,
boolean required,
Consumer<String> onEncounter)
Add an option with argument (with a value to be passed in).
|
<T> void |
addShortOpt(OptionSpecification optionSpecification,
Character opt) |
static GetOpt |
create(Class mainClass,
String restOfParamsDescription)
Constructor.
|
static GetOpt |
create(Class mainClass,
String restOfParamsDescription,
CommandLineProcessingFlavors flavor)
Constructor.
|
static GetOpt |
create(String programName,
String restOfParamsDescription)
Factory method.
|
static GetOpt |
create(String programName,
String restOfParamsDescription,
CommandLineProcessingFlavors flavor)
Factory method.
|
static GetOpt |
createFromReceptacle(Object receptacle,
Class mainClass,
String restOfParamsDescription) |
static GetOpt |
createFromReceptacle(Object receptacle,
Class mainClass,
String restOfParamsDescription,
CommandLineProcessingFlavors flavor) |
static GetOpt |
createFromReceptacle(Object receptacle,
String programName,
String restOfParamsDescription) |
static GetOpt |
createFromReceptacle(Object receptacle,
String programName,
String restOfParamsDescription,
CommandLineProcessingFlavors flavor) |
OptionSpecification |
getLongOpt(String str,
Collection<String> problems) |
Set<OptionSpecification> |
getOptions() |
OptionSpecification |
getShortOptProcessing(Character ch) |
boolean |
isFlagSet(char shortOpt) |
List<String> |
processParams(List<String> params)
Process the command line
|
List<String> |
processParams(String... params)
Process the command line
|
String |
usage() |
void |
usage(StringBuilder errStr)
Generate usage string.
|
public static final CommandLineProcessingFlavors DEFAULT_FLAVOR
public OptionSpecification getShortOptProcessing(Character ch)
public OptionSpecification getLongOpt(String str, Collection<String> problems)
public static GetOpt create(String programName, String restOfParamsDescription)
programName - The name of the program (for the usage message)public static GetOpt create(Class mainClass, String restOfParamsDescription)
mainClass - The class name of the program (for the usage message)public static GetOpt create(String programName, String restOfParamsDescription, CommandLineProcessingFlavors flavor)
programName - The name of the program (for the usage message)public static GetOpt create(Class mainClass, String restOfParamsDescription, CommandLineProcessingFlavors flavor)
mainClass - The class name of the program (for the usage message)public static GetOpt createFromReceptacle(Object receptacle, String programName, String restOfParamsDescription)
public static GetOpt createFromReceptacle(Object receptacle, Class mainClass, String restOfParamsDescription)
public static GetOpt createFromReceptacle(Object receptacle, String programName, String restOfParamsDescription, CommandLineProcessingFlavors flavor)
public static GetOpt createFromReceptacle(Object receptacle, Class mainClass, String restOfParamsDescription, CommandLineProcessingFlavors flavor)
public OptionSpecification addFlag(String documentation, Consumer<Boolean> onEncounter)
documentation - Documentation to display when generating the usage message. May not be
null.IllegalArgumentException - if both ShortOpt and LongOpt are nullIllegalArgumentException - if Documentation is null or zero length (Work with me here!
I'm building a freakin' usage message for you!)IllegalArgumentException - if either ShortOpt or LongOpt has already been addedpublic <T> OptionSpecification addParam(String paramMnemonic, String documentation, boolean required, Class<T> type, Consumer<T> onEncounter)
paramMnemonic - A short name for the parameter. May not be null.documentation - Documentation to display when generating the usage message. May not be
null.required - Whether the option is required to be specified on the command linetype - the type that the argument should be converted toonEncounter - the function to invoke when the option is encounteredGetOptSetupException - if documentation is null or zero lengthGetOptSetupException - if paramMnemonic is null or zero lengthpublic OptionSpecification addParam(String paramMnemonic, String documentation, boolean required, Consumer<String> onEncounter)
paramMnemonic - A short name for the parameter. May not be null.documentation - Documentation to display when generating the usage message. May not be
null.required - Whether the option is required to be specified on the command lineonEncounter - the function to invoke when the option is encounteredGetOptSetupException - if documentation is null or zero lengthGetOptSetupException - if paramMnemonic is null or zero lengthpublic String usage()
public void usage(StringBuilder errStr)
errStr - the output string builderpublic <T> void addShortOpt(OptionSpecification optionSpecification, Character opt)
public <T> void addLongOpt(OptionSpecification optionSpecification, String opt)
public boolean isFlagSet(char shortOpt)
public Set<OptionSpecification> getOptions()
public List<String> processParams(String... params)
params - The command line parametersCommandLineProcessingException - if any of the command line processing semantics are
violated. The message will contain a usage message in
traditional unix style.public List<String> processParams(List<String> params)
params - The command line parametersCommandLineProcessingException - if any of the command line processing semantics are
violatedCopyright © 2017. All rights reserved.