Package net.morimekta.console.args
Class SubCommandSet<SubCommandDef>
- java.lang.Object
-
- net.morimekta.console.args.BaseArgument
-
- net.morimekta.console.args.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 throwArgumentExceptionif 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 SubCommandSetadd(SubCommand<SubCommandDef> subCommand)Add a sub-command to the sub-command-set.SubCommandSetaddAll(SubCommand<SubCommandDef>... subCommands)Add a set of sub-commands to the sub-command-set.intapply(ArgumentList args)Try to apply to the argument.java.lang.StringgetPrefix()Prefix part of the usage usage message.java.lang.StringgetSingleLineUsage()Get the argument's single line usage string.java.lang.StringgetSingleLineUsage(java.lang.String name)Get the single line usage string for a given sub-command.voidprintUsage(java.io.OutputStream out)Print the sub-command list.voidprintUsage(java.io.OutputStream out, boolean showHidden)Print the sub-command list.voidprintUsage(java.io.OutputStream out, java.lang.String name)Print the option usage list for the command.voidprintUsage(java.io.OutputStream out, java.lang.String name, boolean showHidden)Print the option usage list for the command.voidprintUsage(java.io.PrintWriter out)Print the sub-command list.voidprintUsage(java.io.PrintWriter writer, boolean showHidden)Print the sub-command list.voidprintUsage(java.io.PrintWriter writer, java.lang.String name)Print the option usage list for the command.voidprintUsage(java.io.PrintWriter writer, java.lang.String name, boolean showHidden)Print the option usage list.voidvalidate()Called on all the arguments after the parsing is done to validate if all requirements have been passed.-
Methods inherited from class net.morimekta.console.args.BaseArgument
getDefaultValue, getName, getUsage, isHidden, isRepeated, isRequired
-
-
-
-
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:BaseArgumentGet the argument's single line usage string.- Specified by:
getSingleLineUsagein classBaseArgument- Returns:
- The single-line usage string.
-
getPrefix
public java.lang.String getPrefix()
Description copied from class:BaseArgumentPrefix part of the usage usage message.- Specified by:
getPrefixin classBaseArgument- Returns:
- The usage prefix.
-
validate
public void validate() throws ArgumentExceptionDescription copied from class:BaseArgumentCalled on all the arguments after the parsing is done to validate if all requirements have been passed. Should throw anArgumentExceptionif is did not validate with the appropriate error message.- Specified by:
validatein classBaseArgument- Throws:
ArgumentException
-
apply
public int apply(ArgumentList args)
Description copied from class:BaseArgumentTry 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:
applyin classBaseArgument- Parameters:
args- The argument list.- Returns:
- The number of args consumed.
-
-