Class SubparserImpl

    • Field Detail

      • command_

        private final java.lang.String command_
      • aliases_

        private final java.util.List<java.lang.String> aliases_
      • help_

        private java.lang.String help_
    • Method Detail

      • addArgument

        public Argument addArgument​(java.lang.String... nameOrFlags)
        Description copied from interface: ArgumentContainer

        Creates new Argument, adds it to this container and returns it.

        The nameOrFlags is either a single name of positional argument or a list of option strings for named argument, e.g. foo or -f, --foo.

        Specified by:
        addArgument in interface ArgumentContainer
        Parameters:
        nameOrFlags - A name or a list of option strings of new Argument.
        Returns:
        Argument object.
      • addArgumentGroup

        public ArgumentGroup addArgumentGroup​(java.lang.String title)
        Description copied from interface: ArgumentParser

        Creates new ArgumentGroup object and adds to this parser and returns the object.

        The title is printed in help message as a title of this group. ArgumentGroup provides a way to conceptually group up command line arguments.

        Specified by:
        addArgumentGroup in interface ArgumentParser
        Parameters:
        title - The title printed in help message.
        Returns:
        ArgumentGroup object.
      • addMutuallyExclusiveGroup

        public MutuallyExclusiveGroup addMutuallyExclusiveGroup​(java.lang.String title)
        Description copied from interface: ArgumentParser

        Creates new mutually exclusive group, MutuallyExclusiveGroup object, and adds to this parser and returns the object.

        The arguments added to this group are mutually exclusive; if more than one argument belong to the group are specified, an error will be reported. The title is printed in help message as a title of this group.

        Specified by:
        addMutuallyExclusiveGroup in interface ArgumentParser
        Parameters:
        title - The title printed in help message.
        Returns:
        The MutuallyExclusiveGroup object.
      • usage

        public SubparserImpl usage​(java.lang.String usage)
        Description copied from interface: ArgumentParser

        Sets the text to display as usage line. By default, the usage line is calculated from the arguments this object contains.

        If the given usage contains ${prog} string, it will be replaced with the program name given in ArgumentParsers.newArgumentParser(String).

        Specified by:
        usage in interface ArgumentParser
        Parameters:
        usage - usage text
        Returns:
        this
      • epilog

        public SubparserImpl epilog​(java.lang.String epilog)
        Description copied from interface: ArgumentParser
        Sets the text to display after the argument help.
        Specified by:
        epilog in interface ArgumentParser
        Specified by:
        epilog in interface Subparser
        Parameters:
        epilog - The text to display after the argument help.
        Returns:
        this
      • defaultHelp

        public SubparserImpl defaultHelp​(boolean defaultHelp)
        Description copied from interface: ArgumentParser

        If defaultHelp is true, the default values of arguments are printed in help message.

        By default, the default values are not printed in help message.

        Specified by:
        defaultHelp in interface ArgumentParser
        Specified by:
        defaultHelp in interface Subparser
        Parameters:
        defaultHelp - Switch to display the default value in help message.
        Returns:
        this
      • printHelp

        public void printHelp​(java.io.PrintWriter writer)
        Description copied from interface: ArgumentParser
        Prints help message in writer.
        Specified by:
        printHelp in interface ArgumentParser
        Parameters:
        writer - Writer to print message.
      • formatHelp

        public java.lang.String formatHelp()
        Description copied from interface: ArgumentParser
        Returns help message.
        Specified by:
        formatHelp in interface ArgumentParser
        Returns:
        The help message.
      • printUsage

        public void printUsage()
        Description copied from interface: ArgumentParser
        Print a brief description of how the program should be invoked on the command line in stdout.
        Specified by:
        printUsage in interface ArgumentParser
      • printUsage

        public void printUsage​(java.io.PrintWriter writer)
        Description copied from interface: ArgumentParser
        Print a brief description of how the program should be invoked on the command line in writer.
        Specified by:
        printUsage in interface ArgumentParser
        Parameters:
        writer - Writer to print message.
      • formatUsage

        public java.lang.String formatUsage()
        Description copied from interface: ArgumentParser
        Returns a brief description of how the program should be invoked on the command line.
        Specified by:
        formatUsage in interface ArgumentParser
        Returns:
        Usage text.
      • printVersion

        public void printVersion​(java.io.PrintWriter writer)
        Description copied from interface: ArgumentParser
        Prints version string in writer.
        Specified by:
        printVersion in interface ArgumentParser
        Parameters:
        writer - Writer to print version string.
      • formatVersion

        public java.lang.String formatVersion()
        Description copied from interface: ArgumentParser
        Returns version string.
        Specified by:
        formatVersion in interface ArgumentParser
        Returns:
        The version string.
      • setDefault

        public SubparserImpl setDefault​(java.lang.String dest,
                                        java.lang.Object value)
        Description copied from interface: ArgumentParser

        Sets parser-level default value of attribute dest.

        The parser-level defaults always override argument-level defaults.

        Specified by:
        setDefault in interface ArgumentParser
        Specified by:
        setDefault in interface Subparser
        Parameters:
        dest - The attribute name.
        value - The default value.
        Returns:
        this
      • setDefaults

        public SubparserImpl setDefaults​(java.util.Map<java.lang.String,​java.lang.Object> attrs)
        Description copied from interface: ArgumentParser

        Sets parser-level default values from attrs.

        All key-value pair in attrs are registered to parser-level defaults. The parser-level defaults always override argument-level defaults.

        Specified by:
        setDefaults in interface ArgumentParser
        Specified by:
        setDefaults in interface Subparser
        Parameters:
        attrs - The parser-level default values to add.
        Returns:
        this
      • getDefault

        public java.lang.Object getDefault​(java.lang.String dest)
        Description copied from interface: ArgumentParser

        Returns default value of given dest.

        Returns default value set by Argument.setDefault(Object), ArgumentParser.setDefault(String, Object) or ArgumentParser.setDefaults(Map). Please note that while parser-level defaults always override argument-level defaults while parsing, this method examines argument-level defaults first. If no default value is found, then check parser-level defaults. If no default value is found, returns null.

        Specified by:
        getDefault in interface ArgumentParser
        Parameters:
        dest - The attribute name of default value to get.
        Returns:
        The default value of given dest.
      • help

        public SubparserImpl help​(java.lang.String help)
        Description copied from interface: Subparser
        Sets the text to display in help message.
        Specified by:
        help in interface Subparser
        Parameters:
        help - The text to display in help message.
        Returns:
        this
      • help

        public SubparserImpl help​(FeatureControl ctrl)
        Description copied from interface: Subparser

        Sets special value to control help message handling.

        Currently, only FeatureControl.SUPPRESS is available. If it is given, the help entry for this Subparser is not displayed in the help message.

        Specified by:
        help in interface Subparser
        Parameters:
        ctrl - The special value to control help message handling.
        Returns:
        this
      • parseArgs

        public void parseArgs​(java.lang.String[] args,
                              java.lang.Object userData)
                       throws ArgumentParserException
        Description copied from interface: ArgumentParser

        Parses command line arguments.

        Unlike ArgumentParser.parseArgs(String[]), which returns Namespace object, this method stores attributes in given userData. The location to store value is designated using Arg annotations. User don't have to specify Arg for all attributes: the missing attributes are just skipped. This method performs simple List to generic array conversion. For example, user can assign List<Integer> attribute to generic array int[].

        Specified by:
        parseArgs in interface ArgumentParser
        Parameters:
        args - Command line arguments.
        userData - Object to store attributes.
        Throws:
        ArgumentParserException - If an error occurred.
      • parseKnownArgsOrFail

        public Namespace parseKnownArgsOrFail​(java.lang.String[] args,
                                              java.util.List<java.lang.String> unknown)
        Description copied from interface: ArgumentParser

        Just like ArgumentParser.parseArgsOrFail(String[]), but parses only known arguments without throwing exception for unrecognized arguments. If unknown is not null, unrecognized arguments will be stored in it.

        Specified by:
        parseKnownArgsOrFail in interface ArgumentParser
        Parameters:
        args - Command line arguments.
        unknown - Output variable to store unrecognized arguments, or null
        Returns:
        Namespace object.
      • parseKnownArgs

        public void parseKnownArgs​(java.lang.String[] args,
                                   java.util.List<java.lang.String> unknown,
                                   java.util.Map<java.lang.String,​java.lang.Object> attrs)
                            throws ArgumentParserException
        Description copied from interface: ArgumentParser

        Just like ArgumentParser.parseArgs(String[], Map), but parses only known arguments without throwing exception for unrecognized arguments. If unknown is not null, unrecognized arguments will be stored in it.

        Specified by:
        parseKnownArgs in interface ArgumentParser
        Parameters:
        args - Command line arguments.
        unknown - Output variable to store unrecognized arguments, or null
        attrs - Map object to store attributes.
        Throws:
        ArgumentParserException - If an error occurred.
      • parseKnownArgs

        public void parseKnownArgs​(java.lang.String[] args,
                                   java.util.List<java.lang.String> unknown,
                                   java.lang.Object userData)
                            throws ArgumentParserException
        Description copied from interface: ArgumentParser

        Just like ArgumentParser.parseArgs(String[], Object), but parses only known arguments without throwing exception for unrecognized arguments. If unknown is not null, unrecognized arguments will be stored in it.

        Specified by:
        parseKnownArgs in interface ArgumentParser
        Parameters:
        args - Command line arguments.
        unknown - Output variable to store unrecognized arguments, or null
        userData - Object to store attributes.
        Throws:
        ArgumentParserException - If an error occurred.
      • parseKnownArgs

        public void parseKnownArgs​(java.lang.String[] args,
                                   java.util.List<java.lang.String> unknown,
                                   java.util.Map<java.lang.String,​java.lang.Object> attrs,
                                   java.lang.Object userData)
                            throws ArgumentParserException
        Description copied from interface: ArgumentParser

        Just like ArgumentParser.parseArgs(String[], Map, Object), but parses only known arguments without throwing exception for unrecognized arguments. If unknown is not null, unrecognized arguments will be stored in it.

        Specified by:
        parseKnownArgs in interface ArgumentParser
        Parameters:
        args - Command line arguments.
        unknown - Output variable to store unrecognized arguments, or null
        attrs - Map to store attributes.
        userData - Object to store attributes.
        Throws:
        ArgumentParserException - If an error occurred.
      • aliases

        public SubparserImpl aliases​(java.lang.String... alias)
        Description copied from interface: Subparser
        Sets alias names for this Subparser. The alias names must be unique for each Subparsers instance which this object belongs to.
        Specified by:
        aliases in interface Subparser
        Parameters:
        alias - Alias name for this Subparser.
        Returns:
        this
      • printSubparserHelp

        void printSubparserHelp​(java.io.PrintWriter writer,
                                int format_width)
      • getCommand

        public java.lang.String getCommand()