ParameterParser¶
-
public class
ParameterParser¶ General purpose command-line parser accepting (if defined) both single-letter (and space separated value) and full names (and equal-sign separated value). It also supports default values and generation of help based on configured options.
Constructors¶
ParameterParser¶
-
public
ParameterParser()¶ Constructs new
ParameterParserwithout any options and without interactive mode
ParameterParser¶
-
public
ParameterParser(boolean interactiveMode)¶ Constructs new
ParameterParserwithout any options and allowing enabling interactive modeParameters: - interactiveMode – indicates whether interactive mode should be enabled (include it in the options and handle accordingly)
ParameterParser¶
-
public
ParameterParser(List<CommandlineParameter> options, boolean interactiveMode)¶ Constructs new
ParameterParserwith initial options and allowing enabling interactive modeParameters: - options – initial list of available options
- interactiveMode – indicates whether interactive mode should be enabled (include it in the options and handle accordingly)
Methods¶
addOption¶
-
public void
addOption(CommandlineParameter option)¶ Adds
CommandlineParameterto list of available parametersParameters: - option – a
CommandlineParameterthat should be added
Throws: - IllegalArgumentException – is thrown when the same option (either same name or same short-letter) exists in the defined list.
- option – a
addOptions¶
-
public void
addOptions(List<CommandlineParameter> options)¶ Add collection of
CommandlineParameterto available options. Calls internallyParameterParser.addOption(tigase.util.ui.console.CommandlineParameter)Parameters: - options – collection of
CommandlineParameterto be added.
- options – collection of
getHelp¶
getHelp¶
getOptionByLetter¶
-
public Optional<CommandlineParameter>
getOptionByLetter(String letter)¶ Returns
CommandlineParameterthat matches passed parameterParameters: - letter – single-letter identification of the
CommandlineParameter
Returns: an Optional
CommandlineParameterthat matches passed letter.- letter – single-letter identification of the
getOptionByName¶
-
public Optional<CommandlineParameter>
getOptionByName(String commandName)¶ Returns
CommandlineParameterthat matches passed parameterParameters: - commandName – full-name identification of the
CommandlineParameter
Returns: an Optional
CommandlineParameterthat matches passed name.- commandName – full-name identification of the
getOptions¶
-
public List<CommandlineParameter>
getOptions()¶ Retrieves List with all defined
CommandlineParameteroptionsReturns: List with all defined CommandlineParameteroptions
getOptions¶
-
public List<CommandlineParameter>
getOptions(Predicate<? super CommandlineParameter> predicate)¶ Retrieves List with all defined
CommandlineParameteroptions that matches passed PredicateParameters: - predicate – by which list should be filtered
Returns: List of
CommandlineParameterfiltered to matching options.
getOptionsNames¶
-
public List<String>
getOptionsNames(Predicate<? super CommandlineParameter> predicate)¶ Retrieves List with all defined
CommandlineParameteroptions names that matches passed PredicateParameters: - predicate – by which list should be filtered
Returns: List of
CommandlineParameternames filtered to matching options.
parseArgs¶
-
public Properties
parseArgs(String[] args)¶ Main parsing method which takes as an input array of parameters and returns a Properties object with parsed parameter/values. It supports both single letter format (
-X valueas 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)Parameters: - args – an input array of parameters and defined values.
Returns: Properties with parameter/value pairs matching defined options.
removeOption¶
-
public void
removeOption(CommandlineParameter option)¶ Removes given option from list of supported options.
Parameters: - option –
commandlineParameteroption to be removed
- option –