Package org.apache.rat.commandline
Class ArgumentContext
java.lang.Object
org.apache.rat.commandline.ArgumentContext
Provides the context necessary to process various arguments.
- Since:
- 0.17
-
Constructor Summary
ConstructorsConstructorDescriptionArgumentContext(File workingDirectory, org.apache.commons.cli.Options opts, String[] args) Creates a context with an empty configuration.ArgumentContext(File workingDirectory, ReportConfiguration configuration, org.apache.commons.cli.Options opts, String[] args) Creates a context with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcommandLineDescription(org.apache.commons.cli.CommandLine commandLine) Creates a visual description of the CommandLine.getArgs()Gets the arguments that followed all options on the command line.Gets the configuration.org.apache.commons.cli.Option[]Gets the Options from the command line.getOptionValue(org.apache.commons.cli.Option selected) Gets the option value ornullif it is not set on the command line.getOptionValues(org.apache.commons.cli.Option selected) Gets the list of option values from the command line.<T> TgetParsedOptionValue(org.apache.commons.cli.Option selected) Gets the parsed option value from the command line.<T> TgetParsedOptionValue(org.apache.commons.cli.Option selected, Supplier<T> defaultSupplier) Gets the parsed option value from the command line.<T> List<T>getParsedOptionValues(org.apache.commons.cli.Option selected) Gets the parsed option values from the command line.<T> List<T>getParsedOptionValues(org.apache.commons.cli.Option selected, Supplier<List<T>> defaultSupplier) Gets the parsed option values from the command line.Gets the directory name from which relative file names will be resolved.booleanDetermines if option was specified on the command line.booleanhasOption(org.apache.commons.cli.Option option) Determines if option was specified on the command line.voidlogParseException(org.apache.commons.cli.ParseException exception, org.apache.commons.cli.Option opt) Logs a ParseException as a warning and the exception itself as a debug.voidprocessArgs(UIOptionCollection<?> uiOptionCollection) Process the arguments specified in this context.static StringtoString(org.apache.commons.cli.Option option) Gets a logging/debug string describing the Option.
-
Constructor Details
-
ArgumentContext
public ArgumentContext(File workingDirectory, ReportConfiguration configuration, org.apache.commons.cli.Options opts, String[] args) throws org.apache.commons.cli.ParseException Creates a context with the specified configuration.- Parameters:
workingDirectory- the directory from which relative file names will be resolved.configuration- the configuration that is being built.opts- the Options for the command line.args- the arguments for the options.- Throws:
org.apache.commons.cli.ParseException- if the options can not parse the arguments.
-
ArgumentContext
public ArgumentContext(File workingDirectory, org.apache.commons.cli.Options opts, String[] args) throws org.apache.commons.cli.ParseException Creates a context with an empty configuration.- Parameters:
workingDirectory- the directory from which to resolve relative file names.opts- the Options for the command line.args- the arguments for the options.- Throws:
org.apache.commons.cli.ParseException- if the options can not parse the arguments.
-
-
Method Details
-
toString
Gets a logging/debug string describing the Option.- Parameters:
option- the option to describe.- Returns:
- the logging/debug string describing the Option.
-
processArgs
Process the arguments specified in this context. -
getConfiguration
Gets the configuration.- Returns:
- the configuration that is being built.
-
getOptions
public org.apache.commons.cli.Option[] getOptions()Gets the Options from the command line.- Returns:
- the Options from the command line.
-
getArgs
Gets the arguments that followed all options on the command line.- Returns:
- the arguments that followed all options.
-
hasOption
public boolean hasOption(org.apache.commons.cli.Option option) Determines if option was specified on the command line.- Parameters:
option- the option to check.- Returns:
true, if option was specified on the command line.
-
hasOption
Determines if option was specified on the command line.- Parameters:
option- the option to check.- Returns:
true, if option was specified on the command line.
-
getOptionValue
Gets the option value ornullif it is not set on the command line.- Parameters:
selected- the option to retrieve the value for.- Returns:
- the option value or
nullif it is not set.
-
getOptionValues
Gets the list of option values from the command line.- Parameters:
selected- the option to get values for.- Returns:
- The list of options from the command line. Might be an empty list but never
null.
-
getParsedOptionValue
public <T> T getParsedOptionValue(org.apache.commons.cli.Option selected) Gets the parsed option value from the command line.- Type Parameters:
T- the expected parsed value type.- Parameters:
selected- the option to get value for.- Returns:
- the parsed value or
nullif not found.
-
getParsedOptionValue
public <T> T getParsedOptionValue(org.apache.commons.cli.Option selected, Supplier<T> defaultSupplier) Gets the parsed option value from the command line.- Type Parameters:
T- the expected parsed value type.- Parameters:
selected- the option to get value for.defaultSupplier- a supplier of default values.- Returns:
- the parsed value or default value if not found.
-
getParsedOptionValues
Gets the parsed option values from the command line.- Type Parameters:
T- the expected parsed value type.- Parameters:
selected- the option to get value for.- Returns:
- the parsed value list an empty list if not found.
-
getParsedOptionValues
public <T> List<T> getParsedOptionValues(org.apache.commons.cli.Option selected, Supplier<List<T>> defaultSupplier) Gets the parsed option values from the command line.- Type Parameters:
T- the expected parsed value type.- Parameters:
selected- the option to get value for.defaultSupplier- a supplier of default value list.- Returns:
- the parsed value list or default value if not found.
-
getWorkingDirectory
Gets the directory name from which relative file names will be resolved.- Returns:
- the directory name from which relative file names will be resolved.
-
logParseException
public void logParseException(org.apache.commons.cli.ParseException exception, org.apache.commons.cli.Option opt) Logs a ParseException as a warning and the exception itself as a debug.- Parameters:
exception- the parse exception to log.opt- the option being processed.
-
commandLineDescription
Creates a visual description of the CommandLine. This used to be provided by theCommandLine.toString()method, but that has been removed.- Parameters:
commandLine- the command line to format.- Returns:
- a String representation of the command line suitable for debugging.
-