Class SubparsersImpl

  • All Implemented Interfaces:
    Subparsers

    public final class SubparsersImpl
    extends java.lang.Object
    implements Subparsers
    The application code must not use this class directly.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAlias​(SubparserImpl subparser, java.lang.String... alias)
      Adds Subparser alias names for given Subparser.
      SubparserImpl addParser​(java.lang.String command)
      Adds and returns Subparser object with given sub-command name.
      SubparserImpl addParser​(java.lang.String command, boolean addHelp)
      Adds and returns Subparser object with given sub-command name and addHelp.
      SubparserImpl addParser​(java.lang.String command, boolean addHelp, java.lang.String prefixChars)
      Adds and returns Subparser object with given sub-command name, addHelp and prefixChars.
      SubparsersImpl description​(java.lang.String description)
      Sets the text to display to briefly describe sub-commands in the help message.
      SubparsersImpl dest​(java.lang.String dest)
      Sets the name of attribute which the selected command name is stored.
      java.lang.String formatShortSyntax()  
      java.util.Collection<java.lang.String> getCommands()
      Returns collection of the sub-command name under this object.
      java.lang.String getDescription()  
      java.lang.String getTitle()  
      boolean hasSubCommand()  
      SubparsersImpl help​(java.lang.String help)
      Sets the text to display in the help message for sub-commands.
      SubparsersImpl metavar​(java.lang.String metavar)
      Sets the text used to represent sub-commands in help messages.
      void parseArg​(ParseState state, java.util.Map<java.lang.String,​java.lang.Object> opts)  
      void printSubparserHelp​(java.io.PrintWriter writer, int format_width)
      Writes the help message for this and descendants.
      SubparsersImpl title​(java.lang.String title)
      Sets the text to display as a title of sub-commands in the help message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addParser

        public SubparserImpl addParser​(java.lang.String command)
        Description copied from interface: Subparsers

        Adds and returns Subparser object with given sub-command name. The given command must be unique for each Subparsers instance.

        The prefixChars is inherited from main ArgumentParser.

        Specified by:
        addParser in interface Subparsers
        Parameters:
        command - Sub-command name
        Returns:
        Subparser object.
      • addParser

        public SubparserImpl addParser​(java.lang.String command,
                                       boolean addHelp)
        Description copied from interface: Subparsers

        Adds and returns Subparser object with given sub-command name and addHelp. The given command must be unique for each Subparsers instance.

        For addHelp, see ArgumentParsers.newArgumentParser(String, boolean, String). The prefixChars is inherited from main ArgumentParser.

        Specified by:
        addParser in interface Subparsers
        Parameters:
        command - Sub-command name
        addHelp - If true, -h/--help are available. If false, they are not.
        Returns:
        Subparser object
      • addParser

        public SubparserImpl addParser​(java.lang.String command,
                                       boolean addHelp,
                                       java.lang.String prefixChars)
        Description copied from interface: Subparsers

        Adds and returns Subparser object with given sub-command name, addHelp and prefixChars. The given command must be unique for each Subparsers instance.

        For addHelp, see ArgumentParsers.newArgumentParser(String, boolean, String).

        Specified by:
        addParser in interface Subparsers
        Parameters:
        command - Sub-command name
        addHelp - If true, -h/--help are available. If false, they are not.
        prefixChars - The set of characters that prefix optional arguments.
        Returns:
        Subparser object
      • dest

        public SubparsersImpl dest​(java.lang.String dest)
        Description copied from interface: Subparsers
        Sets the name of attribute which the selected command name is stored.
        Specified by:
        dest in interface Subparsers
        Parameters:
        dest - The name of attribute the selected command name is stored.
        Returns:
        this.
      • help

        public SubparsersImpl help​(java.lang.String help)
        Description copied from interface: Subparsers
        Sets the text to display in the help message for sub-commands.
        Specified by:
        help in interface Subparsers
        Parameters:
        help - The text to display in the help message.
        Returns:
        this
      • title

        public SubparsersImpl title​(java.lang.String title)
        Description copied from interface: Subparsers

        Sets the text to display as a title of sub-commands in the help message.

        If either title or description(Subparsers.description(String)) is specified, sub-command help will be displayed in its own group.

        Specified by:
        title in interface Subparsers
        Parameters:
        title - The text to display as a title of sub-commands
        Returns:
        this
      • getTitle

        public java.lang.String getTitle()
      • description

        public SubparsersImpl description​(java.lang.String description)
        Description copied from interface: Subparsers

        Sets the text to display to briefly describe sub-commands in the help message.

        If either description or title(Subparsers.title(String)) is specified, sub-command help will be displayed in its own group.

        Specified by:
        description in interface Subparsers
        Parameters:
        description - The text to display to briefly describe sub-commands
        Returns:
        this
      • getDescription

        public java.lang.String getDescription()
      • metavar

        public SubparsersImpl metavar​(java.lang.String metavar)
        Description copied from interface: Subparsers

        Sets the text used to represent sub-commands in help messages.

        By default, text to represent sub-commands are concatenation of all sub-commands. This method can override this default behavior and sets arbitrary string to use. This is useful if there are many sub-commands and you don't want to show them all.

        Specified by:
        metavar in interface Subparsers
        Parameters:
        metavar - The text used to represent sub-commands in help messages
        Returns:
        this
      • hasSubCommand

        public boolean hasSubCommand()
      • formatShortSyntax

        public java.lang.String formatShortSyntax()
      • printSubparserHelp

        public void printSubparserHelp​(java.io.PrintWriter writer,
                                       int format_width)
        Writes the help message for this and descendants.
        Parameters:
        writer - The writer to output
        format_width - column width
      • getCommands

        public java.util.Collection<java.lang.String> getCommands()
        Returns collection of the sub-command name under this object.
        Returns:
        collection of the sub-comman name
      • addAlias

        public void addAlias​(SubparserImpl subparser,
                             java.lang.String... alias)
        Adds Subparser alias names for given Subparser. For each SubparsersImpl instance, alias names and commands must be unique. If duplication is found, IllegalArgumentException is thrown.
        Parameters:
        subparser - Subparser to add alias names
        alias - alias name