Class Options

java.lang.Object
tripleo.vendor.org_apache_commons_cli.Options
All Implemented Interfaces:
Serializable

public class Options extends Object implements Serializable
Main entry-point into the library.

Options represents a collection of Option objects, which describe the possible options for a command-line.

It may flexibly parse long and short options, with or without values. Additionally, it may parse only a portion of a commandline, allowing for flexible multi-stage parsing.

See Also:
  • Constructor Details

    • Options

      public Options()
  • Method Details

    • addOption

      @NotNull public @NotNull Options addOption(String opt, boolean hasArg, String description)
      Add an option that only contains a short-name.

      It may be specified as requiring an argument.

      Parameters:
      opt - Short single-character name of the option.
      hasArg - flag signalling if an argument is required after this option
      description - Self-documenting description
      Returns:
      the resulting Options instance
    • addOption

      @NotNull public @NotNull Options addOption(String opt, String longOpt, boolean hasArg, String description)
      Add an option that contains a short-name and a long-name.

      It may be specified as requiring an argument.

      Parameters:
      opt - Short single-character name of the option.
      longOpt - Long multi-character name of the option.
      hasArg - flag signalling if an argument is required after this option
      description - Self-documenting description
      Returns:
      the resulting Options instance
    • addOption

      @NotNull public @NotNull Options addOption(@NotNull @NotNull Option opt)
      Adds an option instance
      Parameters:
      opt - the option that is to be added
      Returns:
      the resulting Options instance
    • addOption

      @NotNull public @NotNull Options addOption(String opt, String description)
      Add an option that only contains a short name.

      The option does not take an argument.

      Parameters:
      opt - Short single-character name of the option.
      description - Self-documenting description
      Returns:
      the resulting Options instance
      Since:
      1.3
    • addOptionGroup

      @NotNull public @NotNull Options addOptionGroup(@NotNull @NotNull OptionGroup group)
      Add the specified option group.
      Parameters:
      group - the OptionGroup that is to be added
      Returns:
      the resulting Options instance
    • addRequiredOption

      @NotNull public @NotNull Options addRequiredOption(String opt, String longOpt, boolean hasArg, String description)
      Add an option that contains a short-name and a long-name.

      The added option is set as required. It may be specified as requiring an argument. This method is a shortcut for:

       
       Options option = new Option(opt, longOpt, hasArg, description);
       option.setRequired(true);
       options.add(option);
       
       
      Parameters:
      opt - Short single-character name of the option.
      longOpt - Long multi-character name of the option.
      hasArg - flag signalling if an argument is required after this option
      description - Self-documenting description
      Returns:
      the resulting Options instance
      Since:
      1.4
    • getMatchingOptions

      @NotNull public @NotNull List<String> getMatchingOptions(String opt)
      Gets the options with a long name starting with the name specified.
      Parameters:
      opt - the partial name of the option
      Returns:
      the options matching the partial name specified, or an empty list if none matches
      Since:
      1.3
    • getOption

      public Option getOption(String opt)
      Gets the Option matching the long or short name specified.

      The leading hyphens in the name are ignored (up to 2).

      Parameters:
      opt - short or long name of the Option
      Returns:
      the option represented by opt
    • getOptionGroup

      public OptionGroup getOptionGroup(@NotNull @NotNull Option opt)
      Gets the OptionGroup the opt belongs to.
      Parameters:
      opt - the option whose OptionGroup is being queried.
      Returns:
      the OptionGroup if opt is part of an OptionGroup, otherwise return null
    • getOptions

      @NotNull public @NotNull Collection<Option> getOptions()
      Gets a read-only list of options in this set
      Returns:
      read-only Collection of Option objects in this descriptor
    • getRequiredOptions

      @NotNull public @NotNull List getRequiredOptions()
      Gets the required options.
      Returns:
      read-only List of required options
    • hasLongOption

      public boolean hasLongOption(String opt)
      Returns whether the named Option is a member of this Options.
      Parameters:
      opt - long name of the Option
      Returns:
      true if the named Option is a member of this Options
      Since:
      1.3
    • hasOption

      public boolean hasOption(String opt)
      Returns whether the named Option is a member of this Options.
      Parameters:
      opt - short or long name of the Option
      Returns:
      true if the named Option is a member of this Options
    • hasShortOption

      public boolean hasShortOption(String opt)
      Returns whether the named Option is a member of this Options.
      Parameters:
      opt - short name of the Option
      Returns:
      true if the named Option is a member of this Options
      Since:
      1.3
    • toString

      @NotNull public @NotNull String toString()
      Dump state, suitable for debugging.
      Overrides:
      toString in class Object
      Returns:
      Stringified form of this object