Package org.apache.commons.cli
Class Parser
- java.lang.Object
-
- org.apache.commons.cli.Parser
-
- All Implemented Interfaces:
CommandLineParser
- Direct Known Subclasses:
BasicParser,GnuParser,PosixParser
@Deprecated public abstract class Parser extends java.lang.Object implements CommandLineParser
Deprecated.Since 1.3, the two-pass parsing with the flatten method is not enough flexible to handle complex cases.CreatesCommandLineinstances.
-
-
Field Summary
Fields Modifier and Type Field Description protected CommandLinecmdDeprecated.CommandLine instanceprivate OptionsoptionsDeprecated.Current Optionsprivate java.util.ListrequiredOptionsDeprecated.List of required options strings
-
Constructor Summary
Constructors Constructor Description Parser()Deprecated.Constructs a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcheckRequiredOptions()Deprecated.Throws aMissingOptionExceptionif all of the required options are not present.protected abstract java.lang.String[]flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption)Deprecated.Subclasses must implement this method to reduce theargumentsthat have been passed to the parse method.protected OptionsgetOptions()Deprecated.Gets the options.protected java.util.ListgetRequiredOptions()Deprecated.Gets the required options.CommandLineparse(Options options, java.lang.String[] arguments)Deprecated.Parses the specifiedargumentsbased on the specifiedOptions.CommandLineparse(Options options, java.lang.String[] arguments, boolean stopAtNonOption)Deprecated.Parses the specifiedargumentsbased on the specifiedOptions.CommandLineparse(Options options, java.lang.String[] arguments, java.util.Properties properties)Deprecated.Parses the arguments according to the specified options and properties.CommandLineparse(Options options, java.lang.String[] arguments, java.util.Properties properties, boolean stopAtNonOption)Deprecated.Parses the arguments according to the specified options and properties.voidprocessArgs(Option opt, java.util.ListIterator<java.lang.String> iter)Deprecated.Processes the argument values for the specified Optionoptusing the values retrieved from the specified iteratoriter.protected voidprocessOption(java.lang.String arg, java.util.ListIterator<java.lang.String> iter)Deprecated.Processes the Option specified byargusing the values retrieved from the specified iteratoriter.protected voidprocessProperties(java.util.Properties properties)Deprecated.Sets the values of Options using the values inproperties.protected voidsetOptions(Options options)Deprecated.Sets the options.private voidupdateRequiredOptions(Option opt)Deprecated.Removes the option or its group from the list of expected elements.
-
-
-
Field Detail
-
cmd
protected CommandLine cmd
Deprecated.CommandLine instance
-
options
private Options options
Deprecated.Current Options
-
requiredOptions
private java.util.List requiredOptions
Deprecated.List of required options strings
-
-
Method Detail
-
checkRequiredOptions
protected void checkRequiredOptions() throws MissingOptionExceptionDeprecated.Throws aMissingOptionExceptionif all of the required options are not present.- Throws:
MissingOptionException- if any of the required Options are not present.
-
flatten
protected abstract java.lang.String[] flatten(Options opts, java.lang.String[] arguments, boolean stopAtNonOption) throws ParseException
Deprecated.Subclasses must implement this method to reduce theargumentsthat have been passed to the parse method.- Parameters:
opts- The Options to parse the arguments by.arguments- The arguments that have to be flattened.stopAtNonOption- specifies whether to stop flattening when a non option has been encountered.- Returns:
- a String array of the flattened arguments.
- Throws:
ParseException- if there are any problems encountered while parsing the command line tokens.
-
getOptions
protected Options getOptions()
Deprecated.Gets the options.- Returns:
- the options.
-
getRequiredOptions
protected java.util.List getRequiredOptions()
Deprecated.Gets the required options.- Returns:
- the required options.
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments) throws ParseException
Deprecated.Parses the specifiedargumentsbased on the specifiedOptions.- Specified by:
parsein interfaceCommandLineParser- Parameters:
options- theOptions.arguments- thearguments.- Returns:
- the
CommandLine. - Throws:
ParseException- if there are any problems encountered while parsing the command line tokens.
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, boolean stopAtNonOption) throws ParseException
Deprecated.Parses the specifiedargumentsbased on the specifiedOptions.- Specified by:
parsein interfaceCommandLineParser- Parameters:
options- theOptions.arguments- thearguments.stopAtNonOption- iftruean unrecognized argument stops the parsing and the remaining arguments are added to theCommandLines args list. Iffalsean unrecognized argument triggers a ParseException.- Returns:
- the
CommandLine. - Throws:
ParseException- if an error occurs when parsing the arguments.
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties) throws ParseException
Deprecated.Parses the arguments according to the specified options and properties.- Parameters:
options- the specified Options.arguments- the command line arguments.properties- command line option name-value pairs.- Returns:
- the list of atomic option and value tokens.
- Throws:
ParseException- if there are any problems encountered while parsing the command line tokens.- Since:
- 1.1
-
parse
public CommandLine parse(Options options, java.lang.String[] arguments, java.util.Properties properties, boolean stopAtNonOption) throws ParseException
Deprecated.Parses the arguments according to the specified options and properties.- Parameters:
options- the specified Options.arguments- the command line arguments.properties- command line option name-value pairs.stopAtNonOption- iftruean unrecognized argument stops the parsing and the remaining arguments are added to theCommandLines args list. Iffalsean unrecognized argument triggers a ParseException.- Returns:
- the list of atomic option and value tokens.
- Throws:
ParseException- if there are any problems encountered while parsing the command line tokens.- Since:
- 1.1
-
processArgs
public void processArgs(Option opt, java.util.ListIterator<java.lang.String> iter) throws ParseException
Deprecated.Processes the argument values for the specified Optionoptusing the values retrieved from the specified iteratoriter.- Parameters:
opt- The current Option.iter- The iterator over the flattened command line Options.- Throws:
ParseException- if an argument value is required and it is has not been found.
-
processOption
protected void processOption(java.lang.String arg, java.util.ListIterator<java.lang.String> iter) throws ParseExceptionDeprecated.Processes the Option specified byargusing the values retrieved from the specified iteratoriter.- Parameters:
arg- The String value representing an Option.iter- The iterator over the flattened command line arguments.- Throws:
ParseException- ifargdoes not represent an Option.
-
processProperties
protected void processProperties(java.util.Properties properties) throws ParseExceptionDeprecated.Sets the values of Options using the values inproperties.- Parameters:
properties- The value properties to be processed.- Throws:
ParseException- if there are any problems encountered while processing the properties.
-
setOptions
protected void setOptions(Options options)
Deprecated.Sets the options.- Parameters:
options- the options.
-
updateRequiredOptions
private void updateRequiredOptions(Option opt) throws ParseException
Deprecated.Removes the option or its group from the list of expected elements.- Parameters:
opt- the option.- Throws:
ParseException
-
-