Package org.eclipse.mosaic.lib.util.cli
Class ArgumentsOptionsParser<T>
java.lang.Object
org.eclipse.mosaic.lib.util.cli.ArgumentsOptionsParser<T>
- Type Parameters:
T- class of the parameter object, which later holds the parsed parameter values
Automatically converts a list of arguments and options from the command line into a parameter object.
The parameter object is expected to contain fields annotated with @
CliOption or @CliArgument.
CliArguments follows a strict order and are expected at the beginning of the input command call. After
that, additional CliOptions follow, which have a short and/or long parameter name.-
Constructor Summary
ConstructorsConstructorDescriptionArgumentsOptionsParser(Class<T> parameterClass) Constructs a newArgumentsOptionsParserwith a class of the object, which later holds the argument and option values. -
Method Summary
Modifier and TypeMethodDescriptionfinal org.apache.commons.cli.OptionsThis method provides all options declared in the parameter object this parser has been initialized with.final TparseArguments(String[] args, T targetObject) Parses a list of arguments (POSIX style) and writes the set values into the given parameter object.voidvoidprintHelp(PrintWriter printWriter) Prints the help.transformToArguments(T parameters) Transforms the object, which holds the parameter values into a list of arguments, which can be used to start MOSAIC processes with valid arguments.This method is used to define a usage hint for the respectiveArgumentsOptionsParser.
-
Constructor Details
-
ArgumentsOptionsParser
Constructs a newArgumentsOptionsParserwith a class of the object, which later holds the argument and option values. This must also declare all command line related properties, such as the name of the option and its description. For this, the fields in the given class need to be public and need to be annotated with a @CliArgumentor @CliOption. Everything else is done by this parser.
-
-
Method Details
-
parseArguments
public final T parseArguments(String[] args, T targetObject) throws org.apache.commons.cli.ParseException Parses a list of arguments (POSIX style) and writes the set values into the given parameter object. The parameter object should be of the same class as this parser is initialized with.- Parameters:
args- the input arguments from the command line.targetObject- the object which provides the required fields to fill in values parsed from the list of args.- Throws:
org.apache.commons.cli.ParseException
-
transformToArguments
Transforms the object, which holds the parameter values into a list of arguments, which can be used to start MOSAIC processes with valid arguments.- Throws:
RuntimeException- if a field of the parameter class could not be transformed to an argument
-
printHelp
Prints the help.- Parameters:
printWriter- writer to output help to
-
printHelp
public void printHelp() -
getOptions
public final org.apache.commons.cli.Options getOptions()This method provides all options declared in the parameter object this parser has been initialized with. -
usageHint
This method is used to define a usage hint for the respectiveArgumentsOptionsParser.- Parameters:
usageHint- the hint to be setheader- header for the hintfooter- footer for the hint- Returns:
- the object to chain further methods
-