public class ParameterParser extends Object
Constructor and Description |
---|
ParameterParser()
Constructs new
ParameterParser without any options and without interactive mode |
ParameterParser(boolean interactiveMode)
Constructs new
ParameterParser without any options and allowing enabling interactive mode |
ParameterParser(List<CommandlineParameter> options,
boolean interactiveMode)
Constructs new
ParameterParser with initial options and allowing enabling interactive mode |
Modifier and Type | Method and Description |
---|---|
void |
addOption(CommandlineParameter option)
Adds
CommandlineParameter to list of available parameters |
void |
addOptions(List<CommandlineParameter> options)
Add collection of
CommandlineParameter to available options. |
String |
getHelp()
Generates help output with default instruction.
|
String |
getHelp(String executionCommand) |
Optional<CommandlineParameter> |
getOptionByLetter(String letter)
Returns
CommandlineParameter that matches passed parameter |
Optional<CommandlineParameter> |
getOptionByName(String commandName)
Returns
CommandlineParameter that matches passed parameter |
List<CommandlineParameter> |
getOptions()
Retrieves List with all defined
CommandlineParameter options |
List<CommandlineParameter> |
getOptions(Predicate<? super CommandlineParameter> predicate)
Retrieves List with all defined
CommandlineParameter options that matches passed Predicate |
List<String> |
getOptionsNames(Predicate<? super CommandlineParameter> predicate)
Retrieves List with all defined
CommandlineParameter options names that matches passed Predicate |
Optional<Task> |
getTask() |
boolean |
isInteractiveMode() |
static void |
main(String[] args) |
Properties |
parseArgs(String[] args)
Main parsing method which takes as an input array of parameters and returns a Properties object with parsed
parameter/values.
|
void |
removeOption(CommandlineParameter option)
Removes given option from list of supported options.
|
void |
removeOptionByLetter(String singleLetter)
Removes given option from list of supported options by it's single letter
|
void |
removeOptionByName(String name)
Removes given option from list of supported options by it's full name
|
void |
setTasks(Task[] supportedTasks) |
public ParameterParser()
ParameterParser
without any options and without interactive modepublic ParameterParser(boolean interactiveMode)
ParameterParser
without any options and allowing enabling interactive modeinteractiveMode
- indicates whether interactive mode should be enabled (include it in the options and handle
accordingly)public ParameterParser(List<CommandlineParameter> options, boolean interactiveMode)
ParameterParser
with initial options and allowing enabling interactive modeoptions
- initial list of available optionsinteractiveMode
- indicates whether interactive mode should be enabled (include it in the options and handle
accordingly)public static void main(String[] args)
public void addOption(CommandlineParameter option) throws IllegalArgumentException
CommandlineParameter
to list of available parametersoption
- a CommandlineParameter
that should be addedIllegalArgumentException
- is thrown when the same option (either same name or same short-letter) exists in
the defined list.public void addOptions(List<CommandlineParameter> options)
CommandlineParameter
to available options. Calls internally addOption(tigase.util.ui.console.CommandlineParameter)
options
- collection of CommandlineParameter
to be added.public String getHelp()
public String getHelp(String executionCommand)
executionCommand
- an example of the execution command, for example $ java -cp \"jars/*.jar\"
tigase.util.DBSchemaLoader [options]
public Optional<CommandlineParameter> getOptionByLetter(String letter)
CommandlineParameter
that matches passed parameterletter
- single-letter identification of the CommandlineParameter
CommandlineParameter
that matches passed letter.public Optional<CommandlineParameter> getOptionByName(String commandName)
CommandlineParameter
that matches passed parametercommandName
- full-name identification of the CommandlineParameter
CommandlineParameter
that matches passed name.public List<CommandlineParameter> getOptions()
CommandlineParameter
optionsCommandlineParameter
optionspublic List<CommandlineParameter> getOptions(Predicate<? super CommandlineParameter> predicate)
CommandlineParameter
options that matches passed Predicatepredicate
- by which list should be filteredCommandlineParameter
filtered to matching options.public List<String> getOptionsNames(Predicate<? super CommandlineParameter> predicate)
CommandlineParameter
options names that matches passed Predicatepredicate
- by which list should be filteredCommandlineParameter
names filtered to matching options.public boolean isInteractiveMode()
public Properties parseArgs(String[] args)
-X value
as well as full name (--name=value
). In case no value for defined option was passed but it's defined as required and contains default
value it will be included in the resulting Properties. If interactive mode is enabled, there will be a prompt for
all missing options (defined but not included in passed parameter)args
- an input array of parameters and defined values.public void removeOption(CommandlineParameter option)
option
- commandlineParameter
option to be removedpublic void removeOptionByLetter(String singleLetter)
singleLetter
- identification of the optionpublic void removeOptionByName(String name)
name
- full name identification of the optionpublic void setTasks(Task[] supportedTasks)
Copyright © 2004–2020 "Tigase, Inc.". All rights reserved.