public class CommandLineInteraction extends Object
Note that this class can be run directly (to test raw CLI functionality) with
java -cp target/context-engine-1.0.9-SNAPSHOT.jar com.sdl.context.common.cli.CommandLineInteraction
CLI can be started in debug mode with
java -cp target/context-engine-1.0.9-SNAPSHOT.jar com.sdl.context.common.cli.CommandLineInteraction debug
Modifier and Type | Field and Description |
---|---|
protected static int |
ARGUMENT_INDEX_2 |
protected static int |
ARGUMENT_INDEX_3 |
protected static int |
ARGUMENT_INDEX_4 |
Constructor and Description |
---|
CommandLineInteraction() |
CommandLineInteraction(boolean debug)
Instantiates a new command line interaction.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCommand(String usage,
String description,
String methodName)
Adds the command.
|
protected void |
addCommand(String usage,
String description,
String methodName,
Object commandHandler)
Adds the command.
|
protected boolean |
ask(String... lines)
Ask.
|
protected boolean |
ask(String line)
Ask.
|
protected void |
assertTrue(String line,
boolean expect)
Assert true.
|
void |
batch(Command command) |
void |
batch(String... lines)
Handle a batch of commands.
|
protected void |
display(String line)
Display.
|
protected void |
display(String line,
boolean spaced)
Display.
|
protected void |
display(StringBuilder line)
Display.
|
void |
displayHelp(Command command)
Display help message.
|
protected void |
displayWelcome()
Display Welcome message.
|
void |
doRemote(Command command) |
protected void |
error(String message)
Error.
|
protected void |
fatal(Throwable t)
Fatal.
|
Command |
getCommand(String... lines)
Gets the command.
|
Map<String,CommandConfiguration> |
getCommands()
Gets the commands.
|
boolean |
getDebug() |
boolean |
getDisplayHelpOnStartup() |
int |
getLineLength() |
boolean |
getMaskCharacters() |
String |
getMaskedUserInputWithDefault(String defaultValue,
String line) |
int |
getMaxHistoryLength() |
String |
getName() |
protected String |
getNumberRangeAsString(int start,
int end)
Display number range.
|
protected PrintStream |
getOut() |
int |
getServerPort() |
int |
getServerWaitInMs() |
int |
getUserInputAsInt(String... lines)
Gets the user input as int.
|
protected InputStream |
getUserInputStream() |
String |
getUserInputWithDefault(String defaultValue,
String line) |
void |
handleHistory(Command command) |
protected void |
init()
After properties set.
|
boolean |
isCommandNameCaseInsensitive() |
boolean |
isThrowOnException() |
static void |
main(String[] args)
Start command line.
|
protected void |
print(String message) |
boolean |
quit(Command command) |
void |
run()
Run.
|
void |
run(String commandAsString) |
String |
sendRemoteCommand(int port,
String commandAsString)
Send comment to remote server and return the response from the server.
|
void |
setCommandNameCaseInsensitive(boolean commandNameCaseInsensitive) |
void |
setDebug(boolean debug) |
void |
setDisplayHelpOnStartup(boolean displayHelpOnStartup) |
void |
setLineLength(int lineLength) |
protected void |
setMaskCharacters(boolean maskCharacters) |
void |
setMaxHistoryLength(int maxHistoryLength) |
void |
setName(String name) |
protected void |
setPrependString(String prependString) |
protected void |
setServerPort(int serverPort) |
protected void |
setServerWaitInMs(int serverWaitInMs) |
void |
setThrowOnException(boolean throwOnException) |
protected String |
toBoldBlueString(String s) |
protected String |
toBoldGreenString(String s) |
protected String |
toBoldRedString(String s) |
protected String |
toBoldString(String s) |
protected String |
toBoldYellowString(String s) |
void |
toggleDebugMode(Command command)
Toggle debug mode.
|
protected static final int ARGUMENT_INDEX_2
protected static final int ARGUMENT_INDEX_3
protected static final int ARGUMENT_INDEX_4
public CommandLineInteraction()
public CommandLineInteraction(boolean debug)
public static void main(String[] args)
protected void addCommand(String usage, String description, String methodName) throws CommandLineException
usage
- the usagedescription
- the descriptionmethodName
- the method nameCommandLineException
- the command line exceptionprotected void addCommand(String usage, String description, String methodName, Object commandHandler) throws CommandLineException
usage
- the usagedescription
- the descriptionmethodName
- the method namecommandHandler
- the command handlerCommandLineException
- the command line exceptionprotected void init() throws CommandLineException
CommandLineException
protected boolean ask(String line) throws IOException
line
- the lineIOException
- Signals that an I/O exception has occurred.protected boolean ask(String... lines) throws IOException
lines
- the linesIOException
- Signals that an I/O exception has occurred.protected void assertTrue(String line, boolean expect)
line
- the lineexpect
- the expectpublic void batch(Command command) throws CommandLineException
CommandLineException
public void batch(String... lines) throws CommandLineException
lines
- the linesCommandLineException
- the command line exceptionprotected void display(String line)
line
- the lineprotected void display(String line, boolean spaced)
line
- the linespaced
- the spacedprotected void display(StringBuilder line)
line
- the linepublic void displayHelp(Command command)
command
- the commandpublic void handleHistory(Command command) throws CommandLineException
CommandLineException
protected String getNumberRangeAsString(int start, int end)
start
- the startend
- the endprotected void displayWelcome()
protected void error(String message)
message
- the messageprotected void fatal(Throwable t)
t
- the tpublic Command getCommand(String... lines) throws IOException
lines
- the linesIOException
- Signals that an I/O exception has occurred.public Map<String,CommandConfiguration> getCommands()
public boolean getDisplayHelpOnStartup()
public void setDisplayHelpOnStartup(boolean displayHelpOnStartup)
public int getLineLength()
public void setLineLength(int lineLength)
public int getMaxHistoryLength()
public void setMaxHistoryLength(int maxHistoryLength)
public String getName()
public void setName(String name)
name
- the name to setprotected void setPrependString(String prependString)
public String getMaskedUserInputWithDefault(String defaultValue, String line)
public int getUserInputAsInt(String... lines) throws IOException
lines
- the linesIOException
- Signals that an I/O exception has occurred.protected InputStream getUserInputStream()
protected PrintStream getOut()
public boolean isThrowOnException()
public void setThrowOnException(boolean throwOnException)
throwOnException
- the throwOnException to setpublic boolean quit(Command command)
public void run()
public void run(String commandAsString)
public boolean getDebug()
public void setDebug(boolean debug)
public boolean getMaskCharacters()
protected void setMaskCharacters(boolean maskCharacters)
public void toggleDebugMode(Command command)
command
- the commandpublic void doRemote(Command command) throws IOException
IOException
public String sendRemoteCommand(int port, String commandAsString) throws IOException
port
- port numbercommandAsString
- command as a stringIOException
public boolean isCommandNameCaseInsensitive()
public void setCommandNameCaseInsensitive(boolean commandNameCaseInsensitive)
commandNameCaseInsensitive
- the commandNameCaseInsensitive to setpublic int getServerPort()
protected void setServerPort(int serverPort)
serverPort
- the server port to setpublic int getServerWaitInMs()
protected void setServerWaitInMs(int serverWaitInMs)
protected void print(String message)
Copyright (c) 2014-2021 All Rights Reserved by the RWS Group for and on behalf of its affiliates and subsidiaries