Interface Option

  • All Known Implementing Classes:
    Options

    public interface Option
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.Object> argObjects()
      get remaining non-options args as Objects.
      java.util.List<java.lang.String> args()
      get remaining non-options args as Strings.
      java.lang.String get​(java.lang.String name)
      get value of named option.
      java.util.List<java.lang.String> getList​(java.lang.String name)
      get list of all values for named option.
      int getNumber​(java.lang.String name)
      get value of named option as a Number.
      java.lang.Object getObject​(java.lang.String name)
      get value of named option as an Object.
      java.util.List<java.lang.Object> getObjectList​(java.lang.String name)
      get list of all Object values for named option.
      boolean isSet​(java.lang.String name)
      test whether specified option has been explicitly set.
      Option parse​(java.lang.Object[] argv)
      parse arguments.
      Option parse​(java.lang.Object[] argv, boolean skipArg0)
      parse arguments.
      Option parse​(java.util.List<? extends java.lang.Object> argv)
      parse arguments.
      Option parse​(java.util.List<? extends java.lang.Object> argv, boolean skipArg0)
      parse arguments.
      Option setOptionsFirst​(boolean optionsFirst)
      require options to precede args.
      Option setStopOnBadOption​(boolean stopOnBadOption)
      stop parsing on the first unknown option.
      void usage()
      print usage message to System.err.
      java.lang.IllegalArgumentException usageError​(java.lang.String error)
      print specified usage error to System.err.
    • Method Detail

      • setStopOnBadOption

        Option setStopOnBadOption​(boolean stopOnBadOption)
        stop parsing on the first unknown option. This allows one parser to get its own options and then pass the remaining options to another parser.
        Parameters:
        stopOnBadOption -
      • setOptionsFirst

        Option setOptionsFirst​(boolean optionsFirst)
        require options to precede args. Default is false, so options can appear between or after args.
        Parameters:
        optionsFirst -
      • parse

        Option parse​(java.util.List<? extends java.lang.Object> argv,
                     boolean skipArg0)
        parse arguments. If skipArgv0 is true, then parsing begins at arg1. This allows for commands where argv0 is the command name rather than a real argument.
        Parameters:
        argv -
        skipArg0 -
        Returns:
      • parse

        Option parse​(java.util.List<? extends java.lang.Object> argv)
        parse arguments.
      • parse

        Option parse​(java.lang.Object[] argv,
                     boolean skipArg0)
        parse arguments.
      • parse

        Option parse​(java.lang.Object[] argv)
        parse arguments.
      • isSet

        boolean isSet​(java.lang.String name)
        test whether specified option has been explicitly set.
        Parameters:
        name -
        Returns:
      • get

        java.lang.String get​(java.lang.String name)
        get value of named option. If multiple options given, this method returns the last one. Use getList(String) to get all values.
        Parameters:
        name -
        Returns:
        Throws:
        java.lang.IllegalArgumentException - if value is not a String.
      • getList

        java.util.List<java.lang.String> getList​(java.lang.String name)
        get list of all values for named option.
        Parameters:
        name -
        Returns:
        empty list if option not given and no default specified.
        Throws:
        java.lang.IllegalArgumentException - if all values are not Strings.
      • getObject

        java.lang.Object getObject​(java.lang.String name)
        get value of named option as an Object. If multiple options given, this method returns the last one. Use getObjectList(String) to get all values.
        Parameters:
        name -
        Returns:
      • getObjectList

        java.util.List<java.lang.Object> getObjectList​(java.lang.String name)
        get list of all Object values for named option.
        Parameters:
        name -
        Returns:
      • getNumber

        int getNumber​(java.lang.String name)
        get value of named option as a Number.
        Parameters:
        name -
        Returns:
        Throws:
        java.lang.IllegalArgumentException - if argument is not a Number.
      • args

        java.util.List<java.lang.String> args()
        get remaining non-options args as Strings.
        Returns:
        Throws:
        java.lang.IllegalArgumentException - if args are not Strings.
      • argObjects

        java.util.List<java.lang.Object> argObjects()
        get remaining non-options args as Objects.
        Returns:
      • usage

        void usage()
        print usage message to System.err.
      • usageError

        java.lang.IllegalArgumentException usageError​(java.lang.String error)
        print specified usage error to System.err. You should explicitly throw the returned exception.
        Parameters:
        error -
        Returns:
        IllegalArgumentException