Package com.compomics.util.general
Class CommandLineParser
java.lang.Object
com.compomics.util.general.CommandLineParser
public class CommandLineParser extends Object
This class provides a generic interface for the parsing of command-line
arguments, options and flags.
Arguments are 'stand-alone' Strings, options are preceded by '--' without spaces (like in general GNU practice) and flags are indicated by '-' without spaces.
If there are options that in turn take arguments, these can be specified via a specific constructor.
Arguments are 'stand-alone' Strings, options are preceded by '--' without spaces (like in general GNU practice) and flags are indicated by '-' without spaces.
If there are options that in turn take arguments, these can be specified via a specific constructor.
- Author:
- Lennart Martens
-
Constructor Summary
Constructors Constructor Description CommandLineParser(String[] aCommandLine)
The constructor requires the caller to provide it with a command line arguments String[] that will be the basis of the parsing.CommandLineParser(String[] aCommandLine, String[] aOptionArgs)
This constructor requests the command-line String[] as well as a String[] with a list of options which in turn take a parameter. -
Method Summary
Modifier and Type Method Description String[]
getFlags()
This method will report on all flags that have been found, or return an empty String[] if none were present.String
getOptionParameter(String aOption)
This method will report the option parameter for an option that can take a parameter itself.String[]
getOptions()
This method will report on all options that have been found, or return an empty String[] if none were present.String[]
getParameters()
This method will report on all parameters that have been found, or return an empty String[] if none were present.boolean
hasArguments()
This method returns 'true' if any arguments are present, 'false' otherwise.boolean
hasFlag(String aFlag)
This method test whether the specified flag was set on the command line.
-
Constructor Details
-
CommandLineParser
The constructor requires the caller to provide it with a command line arguments String[] that will be the basis of the parsing.- Parameters:
aCommandLine
- String[] with the command-line arguments.
-
CommandLineParser
This constructor requests the command-line String[] as well as a String[] with a list of options which in turn take a parameter.- Parameters:
aCommandLine
- String[] with the command-line arguments.aOptionArgs
- String[] with the options that take parameters themselves.
-
-
Method Details
-
hasArguments
public boolean hasArguments()This method returns 'true' if any arguments are present, 'false' otherwise.
You are well advised to call this method first, before attempting to retrieve any parameters, as 'null' might be returned.- Returns:
- boolean 'true' if arguments are present, 'false' otherwise.
-
getFlags
This method will report on all flags that have been found, or return an empty String[] if none were present.- Returns:
- String[] with the flags or an empty array if none were found.
-
getOptions
This method will report on all options that have been found, or return an empty String[] if none were present.- Returns:
- String[] with the options or an empty array if none were found.
-
getParameters
This method will report on all parameters that have been found, or return an empty String[] if none were present.- Returns:
- String[] with the parameters or an empty array if none were found.
-
getOptionParameter
This method will report the option parameter for an option that can take a parameter itself. This option has to be specified in the constructor that allows you to pass a String[] with all the options that take a parameter themselves.
Note! If no parameter was present, or the option specified is not an option flagged as taking a parameter, 'null' is returned!- Parameters:
aOption
- String with the option for which the parameter is to be retrieved.- Returns:
- String with the parameter, if found, 'null' otherwise.
-
hasFlag
This method test whether the specified flag was set on the command line.- Parameters:
aFlag
- String with the flag to check. Comparison is case-sensitive!- Returns:
- boolean 'true' if the flag was set, 'false' otherwise.
-