public class CliktCommand implements ParameterHolder
The class CliktCommand is the core of command line interfaces in Clikt.
Command line interfaces created by creating a subclass of class CliktCommand with properties defined with
option and argument. You can then parse argv by calling main, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use parse instead.
Once the command line has been parsed and all of the parameters are populated, run is called.
class CliktCommand,
class CliktCommand,
option,
argument,
main,
parse,
run| Constructor and Description |
|---|
CliktCommand(java.lang.String help,
java.lang.String epilog,
java.lang.String name,
boolean invokeWithoutSubcommand,
boolean printHelpOnEmptyArgs,
java.util.Map<java.lang.String,java.lang.String> helpTags,
java.lang.String autoCompleteEnvvar)
The
class CliktCommand is the core of command line interfaces in Clikt. |
CliktCommand()
The
class CliktCommand is the core of command line interfaces in Clikt. |
| Modifier and Type | Method and Description |
|---|---|
java.util.Map<java.lang.String,java.util.List> |
aliases()
A list of command aliases.
|
protected void |
echo(java.lang.Object message,
boolean trailingNewline,
boolean err,
java.lang.String lineSeparator)
Print the
message to the screen. |
java.lang.String |
getCommandHelp() |
java.lang.String |
getCommandHelpEpilog() |
java.lang.String |
getCommandName() |
Context |
getContext()
This command's context.
|
java.lang.String |
getFormattedHelp()
Return the full help string for this command.
|
java.lang.String |
getFormattedUsage()
Return the usage string for this command.
|
java.util.Map<java.lang.String,java.lang.String> |
getHelpTags()
Extra information about this option to pass to the help formatter.
|
boolean |
getInvokeWithoutSubcommand()
Used when this command has subcommands,
|
java.util.List<java.lang.String> |
getMessages()
All messages issued during parsing.
|
boolean |
getPrintHelpOnEmptyArgs()
If this command is called with no values on the command line,
|
void |
issueMessage(java.lang.String message)
Add a message to be printed after parsing
|
void |
main(java.util.List<java.lang.String> argv)
Parse the command line and print helpful output if any errors occur.
|
void |
main(java.lang.String[] argv) |
void |
parse(java.util.List<java.lang.String> argv,
Context parentContext)
Parse the command line and throw an exception if parsing fails.
|
void |
parse(java.lang.String[] argv,
Context parentContext) |
void |
registerArgument(Argument argument)
Register an argument with this command.
|
void |
registerOption(Option option)
Register an option with this command.
|
void |
registerOption(GroupableOption option)
Register an option with this command or group.
|
void |
registerOptionGroup(ParameterGroup group)
Register a group with this command.
|
java.util.List<java.lang.String> |
registeredSubcommandNames()
The names of all direct children of this command
|
void |
run()
Perform actions after parsing is complete and this command is invoked.
|
protected java.lang.String |
shortHelp()
The help displayed in the commands list when this command is used as a subcommand.
|
java.lang.String |
toString() |
registerOptionpublic CliktCommand(@NotNull
java.lang.String help,
@NotNull
java.lang.String epilog,
@Nullable
java.lang.String name,
boolean invokeWithoutSubcommand,
boolean printHelpOnEmptyArgs,
@NotNull
java.util.Map<java.lang.String,java.lang.String> helpTags,
@Nullable
java.lang.String autoCompleteEnvvar)
The class CliktCommand is the core of command line interfaces in Clikt.
Command line interfaces created by creating a subclass of class CliktCommand with properties defined with
option and argument. You can then parse argv by calling main, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use parse instead.
Once the command line has been parsed and all of the parameters are populated, run is called.
help - The help for this command. The first line is used in the usage string, and the entire string isused in the help output. Paragraphs are automatically re-wrapped to the terminal width.epilog - Text to display at the end of the full help output. It is automatically re-wrapped to theterminal width.name - The name of the program to use in the help output. If not given, it is inferred from the classname.invokeWithoutSubcommand - Used when this command has subcommands, and this command is calledwithout a subcommand. If true, run will be called. By default, a exception PrintHelpMessage is thrown instead.printHelpOnEmptyArgs - If this command is called with no values on the command line, print ahelp message (by throwing exception PrintHelpMessage) if this is true, otherwise run normally.helpTags - Extra information about this option to pass to the help formatter.autoCompleteEnvvar - The envvar to use to enable shell autocomplete script generation. Setto null to disable generation.class CliktCommand,
class CliktCommand,
option,
argument,
main,
parse,
runpublic CliktCommand()
The class CliktCommand is the core of command line interfaces in Clikt.
Command line interfaces created by creating a subclass of class CliktCommand with properties defined with
option and argument. You can then parse argv by calling main, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use parse instead.
Once the command line has been parsed and all of the parameters are populated, run is called.
class CliktCommand,
class CliktCommand,
option,
argument,
main,
parse,
run@NotNull public java.lang.String getCommandName()
@NotNull public java.lang.String getCommandHelp()
@NotNull public java.lang.String getCommandHelpEpilog()
@NotNull public Context getContext()
This command's context.
@NotNull public java.util.List<java.lang.String> getMessages()
All messages issued during parsing.
public void issueMessage(@NotNull
java.lang.String message)
Add a message to be printed after parsing
@NotNull protected java.lang.String shortHelp()
The help displayed in the commands list when this command is used as a subcommand.
@NotNull public java.util.List<java.lang.String> registeredSubcommandNames()
The names of all direct children of this command
public void registerOption(@NotNull
Option option)
Register an option with this command.
This is called automatically for the built in options, but you need to call this if you want to add a custom option.
public void registerOption(@NotNull
GroupableOption option)
Register an option with this command or group.
This is called automatically for the built in options, but you need to call this if you want to add a custom option.
public void registerArgument(@NotNull
Argument argument)
Register an argument with this command.
This is called automatically for the built in arguments, but you need to call this if you want to add a custom argument.
public void registerOptionGroup(@NotNull
ParameterGroup group)
Register a group with this command.
This is called automatically for built in groups, but you need to call this if you want to add a custom group.
@NotNull public java.lang.String getFormattedUsage()
Return the usage string for this command.
@NotNull public java.lang.String getFormattedHelp()
Return the full help string for this command.
@NotNull public java.util.Map<java.lang.String,java.util.List> aliases()
A list of command aliases.
If the user enters a command that matches the a key in this map, the command is replaced with the corresponding value in in map. The aliases aren't recursive, so aliases won't be looked up again while tokens from an existing alias are being parsed.
protected void echo(@Nullable
java.lang.Object message,
boolean trailingNewline,
boolean err,
@NotNull
java.lang.String lineSeparator)
Print the message to the screen.
This is similar to print or println, but converts newlines to the system line separator.
This is equivalent to calling TermUi.echo with the console from the current context.
public void parse(@NotNull
java.util.List<java.lang.String> argv,
@Nullable
Context parentContext)
Parse the command line and throw an exception if parsing fails.
You should use main instead unless you want to handle output yourself.
mainpublic void parse(@NotNull
java.lang.String[] argv,
@Nullable
Context parentContext)
public void main(@NotNull
java.util.List<java.lang.String> argv)
Parse the command line and print helpful output if any errors occur.
This function calls parse and catches and exception CliktErrors that are thrown. Other error are allowed to
pass through.
parse,
exception CliktErrorpublic void main(@NotNull
java.lang.String[] argv)
public void run()
Perform actions after parsing is complete and this command is invoked.
This is called after command line parsing is complete. If this command is a subcommand, this will only be called if the subcommand is invoked.
If one of this command's subcommands is invoked, this is called before the subcommand's arguments are parsed.
@NotNull public java.lang.String toString()
public boolean getInvokeWithoutSubcommand()
Used when this command has subcommands,
and this command is calledwithout a subcommand. If true, run will be called. By default, a exception PrintHelpMessage is thrown instead.
run,
exception PrintHelpMessagepublic boolean getPrintHelpOnEmptyArgs()
If this command is called with no values on the command line,
print ahelp message (by throwing exception PrintHelpMessage) if this is true, otherwise run normally.
exception PrintHelpMessage@NotNull public java.util.Map<java.lang.String,java.lang.String> getHelpTags()
Extra information about this option to pass to the help formatter.