public abstract class ConsoleCommand extends Object
Console commands allow you to interact with your microservice through the system console.
Console commands are associated with the microservice through the following:
MicroserviceBuilder.consoleCommands(Class...)
method.
For example, the HelpCommand
is used to provide help on other commands.
Running class 'JettyMicroservice' using config file 'examples.cfg'. Server started on port 10000 List of available commands: exit -- Shut down service restart -- Restarts service help -- Commands help echo -- Echo command > help help NAME help -- Commands help SYNOPSIS help [command] DESCRIPTION When called without arguments, prints the descriptions of all available commands. Can also be called with one or more arguments to get detailed information on a command. EXAMPLES List all commands: > help List help on the help command: > help help >
The arguments are available as an Args
object which allows for easy accessed to parsed command lines.
Some simple examples of valid command lines:
Constructor and Description |
---|
ConsoleCommand() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
execute(Scanner in,
PrintWriter out,
Args args)
Executes a command.
|
String |
getDescription()
Returns localized details of the command.
|
String |
getExamples()
Returns localized examples of the command.
|
String |
getInfo()
Returns a one-line localized description of the command.
|
abstract String |
getName()
Returns the name of the command.
|
String |
getSynopsis()
Returns the usage synopsis of the command.
|
public ConsoleCommand()
public abstract String getName()
Example:
public String getSynopsis()
Example:
The default implementation just returns the name, which implies the command takes no additional arguments.
public String getInfo()
The locale should be the system locale.
public String getDescription()
The locale should be the system locale.
public String getExamples()
The locale should be the system locale.
public abstract boolean execute(Scanner in, PrintWriter out, Args args) throws Exception
in
- The console reader.out
- The console writer.args
- The command arguments. The first argument is always the command itself.Exception
- Any thrown exception will simply be sent to STDERR.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.