Package fmpp.util

Class ArgsParser.OptionDefinition

java.lang.Object
fmpp.util.ArgsParser.OptionDefinition
All Implemented Interfaces:
Cloneable
Enclosing class:
ArgsParser

public class ArgsParser.OptionDefinition extends Object implements Cloneable
Describes and option. It does not store the actual value of the option after parsing; it is just the definition of the option.
  • Constructor Details

    • OptionDefinition

      public OptionDefinition()
  • Method Details

    • property

      public ArgsParser.OptionDefinition property(String pName)
      Sets the property name for this option. If you don't override the property name with this, it will be the long-name of the option if the option has long-name, otherwise the short-name of the option.
      See Also:
    • propertyValue

      public ArgsParser.OptionDefinition propertyValue(String value)
      Sets the property value for this option. This only allowed for options that do no support argument, as the value of options that has argument will be the actual value of the argument. If you don't override the property value with this, it will be "" (0 length String) for those options.
      Throws:
      IllegalArgumentException - if the option has argument.
      See Also:
    • property

      public ArgsParser.OptionDefinition property(String propertyName, String propertyValue)
      Convenience method; same as calling property(String) and then propertyValue. This method only applies for options that do no support argument.
      See Also:
    • group

      public ArgsParser.OptionDefinition group(String propertyName)
      Convenience method; same as calling property(propertyName, optionName), where optionName is the long-name if that exists, otherwise the short-name. This method only applies for options that do no support argument.
      See Also:
    • implied

      public ArgsParser.OptionDefinition implied()
      Ensures that the option will be seemingly present if the args[] does not contains this option or any other option that mutually excludes this option. Note that if the option supports argument, you have to use implied(String).
      Throws:
      IllegalArgumentException - if the option has argument.
      See Also:
    • implied

      public ArgsParser.OptionDefinition implied(String impliedArg)
      Ensures that the option will be seemingly present with the given argument value if args[] does not contains this option, or any other option that mutually excludes this option. This version of the method applies only for options that support argument.
      Throws:
      IllegalArgumentException - if the option has no argument.
      See Also:
    • defaultArg

      public ArgsParser.OptionDefinition defaultArg(String defaultValue)
      Gives default argument value for an option that supports arguments, thus it will be optional to specify the argument value in the command-line.

      Note that introducing default value for an option is not a backward compatible step. For example if "color" has no default value, then "--color red" is interpreted as "color" has an argument that is "red". But, if "color" has a default value, then it is interpreted as "color" has the default value, and we have a non-option "red". Of coruse, there would not be problem if we use "--color=red".

    • desc

      public ArgsParser.OptionDefinition desc(String desc)
      Sets the description (used in help) of the option.
    • hide

      public void hide()
      Hides option, that is, it will not be shown in the option help.
    • copy

      public ArgsParser.OptionDefinition copy(String shortName, String longName)
      Creates a copy of the option with different short- and long-name, but with the same property name (and other attributes). This is mostly useful to create alias options.
      Parameters:
      longName - the long-name of option or null. Do not use the long-name=ARGNAME form here.
      shortName - the short-name of option or null. Do not use the s=ARGNAME form here.
      Returns:
      the newly created OptionDefinition.
      Throws:
      IllegalArgumentException - If an option with the same long-name or short-name is already added, or if the given long- or short-name is malformed.
    • getArgName

      public String getArgName()
      Returns the name of the argument, or null if the option does not support argument.
    • getDefaultArg

      public String getDefaultArg()
      Returns the default argument of the option, or null if the option has no default argument.
    • getDescription

      public String getDescription()
      Returns the description of the option, or null if no description is available.
    • getLongName

      public String getLongName()
      Returns the long-name of the option, or null if the option has no long-name.
    • getShortName

      public String getShortName()
      Returns the short-name of the option, or null if the option has no short-name.