Class CommandLineExtracter

Object
CommandLineExtracter

public class CommandLineExtracter extends Object
Adds methods to CommandLine for querying and extracting options, with and without arguments.
Author:
Owen Feehan
  • Constructor Details

    • CommandLineExtracter

      public CommandLineExtracter(org.apache.commons.cli.CommandLine line)
      Creates a new CommandLineExtracter instance.
      Parameters:
      line - The command-line from which options are extracted.
  • Method Details

    • hasOption

      public boolean hasOption(String option)
      Identical to CommandLine.hasOption(java.lang.String).
      Parameters:
      option - short-name of option
      Returns:
      true iff option exists on the command-line, irrespective of if arguments are present or not
    • hasOptionWithoutArgument

      public boolean hasOptionWithoutArgument(String option)
      Checks if an option exists, but without any argument(s) specified.
      Parameters:
      option - short-name of option
      Returns:
      true iff option exists on the command-line and no argument is specified.
    • ifPresentSingle

      public void ifPresentSingle(String optionName, CheckedConsumer<String,ExperimentExecutionException> consumer) throws ExperimentExecutionException
      Executes a Consumer if an option is present - allowing that option to occur only once.
      Parameters:
      optionName - the short-name of the option, which should be capable of accepting a single-argument
      consumer - a consumer that accepts a single argument as a string, an empty-string if no argument is provided.
      Throws:
      ExperimentExecutionException - if thrown by consumer or if the option is specified multiple times.
    • ifPresentMultiple

      public void ifPresentMultiple(String optionName, CheckedConsumer<String[],ExperimentExecutionException> consumer) throws ExperimentExecutionException
      Executes a Consumer if an option is present - allowing that option to occur multiple times.
      Parameters:
      optionName - the short-name of the option, which should be capable of accepting a single-argument
      consumer - a consumer that accepts a single argument as a string, an empty-string if no argument is provided.
      Throws:
      ExperimentExecutionException - if thrown by consumer or if the option is specified multiple times.