Class Parser


  • public final class Parser
    extends java.lang.Object
    Defines the CLI argument parser of a Command.
    • Method Detail

      • getPositionalName

        public java.util.Optional<java.lang.String> getPositionalName()
      • getPositionalHelp

        public java.util.Optional<java.lang.String> getPositionalHelp()
      • parse

        public Arguments parse​(java.lang.String[] args)
        Parses command line arguments in an Arguments object.

        All arguments after the first argument that does not start with "-" or after "--" are treated as positional options. Arguments that come before this must be present in the argument spec returned by the command. Any encountered unknown argument will throw an exception. Arguments that expect a value and do not find one will throw an exception.

        Parameters:
        args - Arguments to parse.
        Returns:
        Returns the parsed arguments.
        Throws:
        CliError - if the arguments are invalid.
      • parse

        public Arguments parse​(java.lang.String[] args,
                               int offset)
        Parses command line arguments in an Arguments object.
        Parameters:
        args - Arguments to parse.
        offset - Number of arguments to skip before parsing.
        Returns:
        Returns the parsed arguments.
        Throws:
        CliError - if the arguments are invalid.
        See Also:
        parse(String[])