Class SubCommandSet<SubCommandDef>

  • Type Parameters:
    SubCommandDef - The sub-command interface.

    public class SubCommandSet<SubCommandDef>
    extends BaseArgument
    The argument part of the sub-command. The sub-command set is a collection of sub-commands that react to CLI arguments. It will always trigger (and throw ArgumentException if not valid), so the sub-command must be added last.
    • Constructor Summary

      Constructors 
      Constructor Description
      SubCommandSet​(java.lang.String name, java.lang.String usage, java.util.function.Consumer<SubCommandDef> consumer)
      Create a sub-command set.
      SubCommandSet​(java.lang.String name, java.lang.String usage, java.util.function.Consumer<SubCommandDef> consumer, java.lang.String defaultValue)
      Create an optional sub-command set.
      SubCommandSet​(java.lang.String name, java.lang.String usage, java.util.function.Consumer<SubCommandDef> consumer, java.lang.String defaultValue, boolean required, ArgumentOptions options)
      Create an optional sub-command set.
      SubCommandSet​(java.lang.String name, java.lang.String usage, java.util.function.Consumer<SubCommandDef> consumer, ArgumentOptions options)
      Create an optional sub-command set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SubCommandSet add​(SubCommand<SubCommandDef> subCommand)
      Add a sub-command to the sub-command-set.
      SubCommandSet addAll​(SubCommand<SubCommandDef>... subCommands)
      Add a set of sub-commands to the sub-command-set.
      int apply​(ArgumentList args)
      Try to apply to the argument.
      java.lang.String getPrefix()
      Prefix part of the usage usage message.
      java.lang.String getSingleLineUsage()
      Get the argument's single line usage string.
      java.lang.String getSingleLineUsage​(java.lang.String name)
      Get the single line usage string for a given sub-command.
      void printUsage​(java.io.OutputStream out)
      Print the sub-command list.
      void printUsage​(java.io.OutputStream out, boolean showHidden)
      Print the sub-command list.
      void printUsage​(java.io.OutputStream out, java.lang.String name)
      Print the option usage list for the command.
      void printUsage​(java.io.OutputStream out, java.lang.String name, boolean showHidden)
      Print the option usage list for the command.
      void printUsage​(java.io.PrintWriter out)
      Print the sub-command list.
      void printUsage​(java.io.PrintWriter writer, boolean showHidden)
      Print the sub-command list.
      void printUsage​(java.io.PrintWriter writer, java.lang.String name)
      Print the option usage list for the command.
      void printUsage​(java.io.PrintWriter writer, java.lang.String name, boolean showHidden)
      Print the option usage list.
      void validate()
      Called on all the arguments after the parsing is done to validate if all requirements have been passed.
      • Methods inherited from class java.lang.Object

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

      • SubCommandSet

        public SubCommandSet​(java.lang.String name,
                             java.lang.String usage,
                             java.util.function.Consumer<SubCommandDef> consumer)
        Create a sub-command set.
        Parameters:
        name - The name of the sub-command.
        usage - The usage description.
        consumer - The sub-command consumer.
      • SubCommandSet

        public SubCommandSet​(java.lang.String name,
                             java.lang.String usage,
                             java.util.function.Consumer<SubCommandDef> consumer,
                             ArgumentOptions options)
        Create an optional sub-command set.
        Parameters:
        name - The name of the sub-command.
        usage - The usage description.
        consumer - The sub-command consumer.
        options - Extra argument options.
      • SubCommandSet

        public SubCommandSet​(java.lang.String name,
                             java.lang.String usage,
                             java.util.function.Consumer<SubCommandDef> consumer,
                             java.lang.String defaultValue)
        Create an optional sub-command set.
        Parameters:
        name - The name of the sub-command.
        usage - The usage description.
        consumer - The sub-command consumer.
        defaultValue - The default sub-command.
      • SubCommandSet

        public SubCommandSet​(java.lang.String name,
                             java.lang.String usage,
                             java.util.function.Consumer<SubCommandDef> consumer,
                             java.lang.String defaultValue,
                             boolean required,
                             ArgumentOptions options)
        Create an optional sub-command set.
        Parameters:
        name - The name of the sub-command.
        usage - The usage description.
        consumer - The sub-command consumer.
        defaultValue - The default sub-command.
        required - If the sub-command is required.
        options - Extra argument options.
    • Method Detail

      • add

        public SubCommandSet add​(SubCommand<SubCommandDef> subCommand)
        Add a sub-command to the sub-command-set.
        Parameters:
        subCommand - The sub-command to add.
        Returns:
        The sub-command-set.
      • addAll

        @SafeVarargs
        public final SubCommandSet addAll​(SubCommand<SubCommandDef>... subCommands)
        Add a set of sub-commands to the sub-command-set.
        Parameters:
        subCommands - The sub-commands to add.
        Returns:
        The sub-command-set.
      • printUsage

        public void printUsage​(java.io.OutputStream out)
        Print the sub-command list.
        Parameters:
        out - The output stream.
      • printUsage

        public void printUsage​(java.io.PrintWriter out)
        Print the sub-command list.
        Parameters:
        out - The output stream.
      • printUsage

        public void printUsage​(java.io.OutputStream out,
                               boolean showHidden)
        Print the sub-command list.
        Parameters:
        out - The output stream.
        showHidden - If hidden sub-commands should be printed.
      • printUsage

        public void printUsage​(java.io.PrintWriter writer,
                               boolean showHidden)
        Print the sub-command list.
        Parameters:
        writer - The output printer.
        showHidden - Whether to show hidden options.
      • printUsage

        public void printUsage​(java.io.OutputStream out,
                               java.lang.String name)
        Print the option usage list for the command.
        Parameters:
        out - The output stream.
        name - The sub-command to print help for.
      • printUsage

        public void printUsage​(java.io.OutputStream out,
                               java.lang.String name,
                               boolean showHidden)
        Print the option usage list for the command.
        Parameters:
        out - The output stream.
        name - The sub-command to print help for.
        showHidden - If hidden sub-commands should be shown.
      • printUsage

        public void printUsage​(java.io.PrintWriter writer,
                               java.lang.String name)
        Print the option usage list for the command.
        Parameters:
        writer - The output printer.
        name - The sub-command to print help for.
      • getSingleLineUsage

        public java.lang.String getSingleLineUsage​(java.lang.String name)
        Get the single line usage string for a given sub-command.
        Parameters:
        name - The sub-command to print help for.
        Returns:
        The usage string.
      • printUsage

        public void printUsage​(java.io.PrintWriter writer,
                               java.lang.String name,
                               boolean showHidden)
        Print the option usage list. Essentially printed as a list of options with the description indented where it overflows the available line width.
        Parameters:
        writer - The output printer.
        name - The sub-command to print help for.
        showHidden - Whether to show hidden options.
      • getSingleLineUsage

        public java.lang.String getSingleLineUsage()
        Description copied from class: BaseArgument
        Get the argument's single line usage string.
        Specified by:
        getSingleLineUsage in class BaseArgument
        Returns:
        The single-line usage string.
      • getPrefix

        public java.lang.String getPrefix()
        Description copied from class: BaseArgument
        Prefix part of the usage usage message.
        Specified by:
        getPrefix in class BaseArgument
        Returns:
        The usage prefix.
      • apply

        public int apply​(ArgumentList args)
        Description copied from class: BaseArgument
        Try to apply to the argument. The method shoud return 0 if the argument is rejected, otherwise the number of argument strings that was consumed.
        Specified by:
        apply in class BaseArgument
        Parameters:
        args - The argument list.
        Returns:
        The number of args consumed.