public class 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
OptionWithValuesKt.option
and ArgumentKt.argument
. You can then parse argv
by calling CliktCommand.main
, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use CliktCommand.parse
instead.
Once the command line has been parsed and all of the parameters are populated, CliktCommand.run
is called.
Constructor and Description |
---|
CliktCommand(java.lang.String help,
java.lang.String epilog,
java.lang.String name,
boolean invokeWithoutSubcommand)
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.
|
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.
|
boolean |
getInvokeWithoutSubcommand()
Used when this command has subcommands,
|
void |
main(java.lang.String[] argv)
Parse the command line and print helpful output if any errors occur.
|
void |
parse(java.lang.String[] argv,
Context context)
Parse the command line and throw an exception if parsing fails.
|
void |
registerArgument(Argument argument)
Register an argument with this command.
|
void |
registerOption(Option option)
Register an option 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.
|
java.lang.String |
shortHelp()
The help displayed in the commands list when this command is used as a subcommand.
|
public CliktCommand(java.lang.String help, java.lang.String epilog, java.lang.String name, boolean invokeWithoutSubcommand)
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
OptionWithValuesKt.option
and ArgumentKt.argument
. You can then parse argv
by calling CliktCommand.main
, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use CliktCommand.parse
instead.
Once the command line has been parsed and all of the parameters are populated, CliktCommand.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, CliktCommand.run
will be called. By default, a exception PrintHelpMessage
is thrown instead.help
- The help for this command. The first line is used in the usage string, and the entire string is
used 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 the
terminal width.name
- The name of the program to use in the help output. If not given, it is inferred from the class
name.invokeWithoutSubcommand
- Used when this command has subcommands, and this command is called
without a subcommand. If true, CliktCommand.run
will be called. By default, a exception PrintHelpMessage
is thrown instead.class CliktCommand
,
class CliktCommand
,
OptionWithValuesKt.option
,
ArgumentKt.argument
,
CliktCommand.main
,
CliktCommand.parse
,
CliktCommand.run
public 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
OptionWithValuesKt.option
and ArgumentKt.argument
. You can then parse argv
by calling CliktCommand.main
, which will take care of printing
errors and help to the user. If you want to handle output yourself, you can use CliktCommand.parse
instead.
Once the command line has been parsed and all of the parameters are populated, CliktCommand.run
is called.
public java.lang.String getCommandName()
public java.lang.String getCommandHelp()
public java.lang.String getCommandHelpEpilog()
public Context getContext()
This command's context.
CliktCommand.parse
or CliktCommand.main
are called.public java.lang.String shortHelp()
The help displayed in the commands list when this command is used as a subcommand.
public java.util.List<java.lang.String> registeredSubcommandNames()
The names of all direct children of this command
public void registerOption(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 registerArgument(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 java.lang.String getFormattedUsage()
Return the usage string for this command.
public java.lang.String getFormattedHelp()
Return the full help string for this command.
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 wile token from an existing alias are being parsed.
public void parse(java.lang.String[] argv, Context context)
Parse the command line and throw an exception if parsing fails.
You should use CliktCommand.main
instead unless you want to handle output yourself.
CliktCommand.main
public void main(java.lang.String[] argv)
Parse the command line and print helpful output if any errors occur.
This function calls CliktCommand.parse
and catches and exception CliktError
s that are thrown. Other error are allowed to
pass through.
CliktCommand.parse
,
exception CliktError
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.
public boolean getInvokeWithoutSubcommand()
Used when this command has subcommands,
and this command is calledwithout a subcommand. If true, CliktCommand.run
will be called. By default, a exception PrintHelpMessage
is thrown instead.
CliktCommand.run
,
exception PrintHelpMessage