Class ArgumentContext

java.lang.Object
org.apache.rat.commandline.ArgumentContext

public final class ArgumentContext extends Object
Provides the context necessary to process various arguments.
Since:
0.17
  • 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

      public static String toString(org.apache.commons.cli.Option option)
      Gets a logging/debug string describing the Option.
      Parameters:
      option - the option to describe.
      Returns:
      the logging/debug string describing the Option.
    • processArgs

      public void processArgs(UIOptionCollection<?> uiOptionCollection)
      Process the arguments specified in this context.
    • getConfiguration

      public ReportConfiguration 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

      public List<String> 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

      public boolean hasOption(String 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.
    • getOptionValue

      public String getOptionValue(org.apache.commons.cli.Option selected)
      Gets the option value or null if it is not set on the command line.
      Parameters:
      selected - the option to retrieve the value for.
      Returns:
      the option value or null if it is not set.
    • getOptionValues

      public List<String> getOptionValues(org.apache.commons.cli.Option selected)
      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 null if 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

      public <T> List<T> getParsedOptionValues(org.apache.commons.cli.Option selected)
      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

      public DocumentName 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

      public String commandLineDescription()
      Creates a visual description of the CommandLine. This used to be provided by the CommandLine.toString() method, but that has been removed.
      Returns:
      a String representation of the command line suitable for debugging.