Package org.openstreetmap.josm.tools
Class OptionParser
java.lang.Object
org.openstreetmap.josm.tools.OptionParser
A replacement of getopt.
Allows parsing command line options
- Since:
- 14415
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceprivate static classstatic enumHow often an option may / must be specified on the command line.static classException thrown when an option cannot be parsed. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HashMap<String,OptionParser.AvailableOption> private final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddArgumentParameter(String optionName, OptionParser.OptionCount count, Consumer<String> handler) Add a parameter that expects a string attribute.addFlagParameter(String optionName, Runnable handler) Adds an option that may be used as a flag, e.g.addShortAlias(String optionName, String shortName) Adds an alias for the long option --optionName to the short version -nameprivate voidcheckOptionName(String optionName) private OptionParser.AvailableOptionfindParameter(String optionName) parseOptions(List<String> arguments) Parses the options.parseOptionsOrExit(List<String> arguments) Same asparseOptions(List), but exits if option parsing fails.
-
Field Details
-
availableOptions
-
program
-
-
Constructor Details
-
OptionParser
Create a new option parser.- Parameters:
program- The program name.
-
-
Method Details
-
addShortAlias
Adds an alias for the long option --optionName to the short version -name- Parameters:
optionName- The long optionshortName- The short version- Returns:
- this
OptionParser
-
addFlagParameter
Adds an option that may be used as a flag, e.g. --debug- Parameters:
optionName- The parameter namehandler- The handler that is called when the flag is encountered.- Returns:
- this
OptionParser
-
checkOptionName
-
addArgumentParameter
public OptionParser addArgumentParameter(String optionName, OptionParser.OptionCount count, Consumer<String> handler) Add a parameter that expects a string attribute. E.g.: --config=/path/to/file- Parameters:
optionName- The name of the parameter.count- The number of times the parameter may occur.handler- A function that gets the current object and the parameter. It should throw anOptionParser.OptionParseExceptionif the parameter cannot be handled / is invalid.- Returns:
- this
OptionParser
-
parseOptionsOrExit
Same asparseOptions(List), but exits if option parsing fails.- Parameters:
arguments- The options- Returns:
- The remaining program arguments that are no options.
-
parseOptions
Parses the options.It first checks if all required options are present, if all options are known and validates the option count.
Then, all option handlers are called in the order in which the options are encountered.
- Parameters:
arguments- Program arguments- Returns:
- The remaining program arguments that are no options.
- Throws:
OptionParser.OptionParseException- The error to display if option parsing failed.
-
findParameter
-