Package readycli
Class CLI
java.lang.Object
readycli.CLI
- All Implemented Interfaces:
- java.io.Serializable
public final class CLI
extends java.lang.Object
implements java.io.Serializable
Represents a CLI (Command-Line Interface). A CLI object can be created
 through the 
create(String, String) method. A CLI object is
 responsible of interacting with the user on the given out and in streams. A
 CLI object allows to add new commands and to remove existing ones. Moreover,
 a CLI object allows to show an application title when it starts and a command
 prompt, that can be modified at runtime. A CLI object is not active and it
 must be executed through the execute(PrintStream, InputStream)
 method.- Author:
- Salvatore Giampa'
- See Also:
- Serialized Form
- 
Method SummaryModifier and Type Method Description CLIaddCommand(java.lang.String name, Command command)Adds a command to theCLI.static CLIcreate()Creates a newCLIobject with a null application title and a null command prompt.static CLIcreate(java.lang.String title)Creates a newCLIobject with a null application title and a null command prompt.static CLIcreate(java.lang.String title, java.lang.String commandPrompt)Creates a newCLIobject with the given application title and command prompt.voidexecute()Starts executing theCLI, as theexecute(PrintStream, InputStream)method does, but on the standardI/O.voidexecute(java.io.PrintStream output, java.io.InputStream input)Starts executing theCLIuntil the current thread is interrupted.java.lang.StringgetCommandPrompt()Gets the current command prompt that is shown just before theCLIstarts to listen for the next command.java.lang.StringgetTitle()Gets the current title.voidprintHelp(java.io.PrintStream output)Lists the available commands of thisCLIon the given out stream.CLIremoveCommand(java.lang.String name)Removes a command to theCLI.CLIsetCommandPrompt(java.lang.String commandPrompt)Sets a new command prompt to show just before theCLIstarts to listen for the next command.CLIsetTitle(java.lang.String title)Sets theCLItitle (e.g. the application name and the version).
- 
Method Details- 
createCreates a newCLIobject with the given application title and command prompt.- Parameters:
- title- the title to show when the- CLI(String, String)starts (e.g. the application name and the version)
- commandPrompt- the prompt to show before starting to listen for commands (e.g. the current directory path)
- Returns:
- the new CLIobject
 
- 
createCreates a newCLIobject with a null application title and a null command prompt.- Returns:
- the new CLIobject
 
- 
createCreates a newCLIobject with a null application title and a null command prompt.- Parameters:
- title- the title to show when the- CLI(String, String)starts (e.g. the application name and the version)
- Returns:
- the new CLIobject
 
- 
addCommandAdds a command to theCLI.
- 
removeCommandRemoves a command to theCLI.- Parameters:
- name- the name of the command to remove
- Returns:
- this same CLIobject
 
- 
setCommandPromptSets a new command prompt to show just before theCLIstarts to listen for the next command.- Parameters:
- commandPrompt- the new command prompt
- Returns:
- this same CLIobject
 
- 
getCommandPromptpublic java.lang.String getCommandPrompt()Gets the current command prompt that is shown just before theCLIstarts to listen for the next command.- Returns:
- the current command prompt as string
 
- 
setTitleSets theCLItitle (e.g. the application name and the version).
- 
getTitlepublic java.lang.String getTitle()Gets the current title.- Returns:
- the current title as string
 
- 
printHelppublic void printHelp(java.io.PrintStream output)Lists the available commands of thisCLIon the given out stream.- Parameters:
- output- the out stream on which the list of command must be wrote.
 
- 
executepublic void execute()Starts executing theCLI, as theexecute(PrintStream, InputStream)method does, but on the standardI/O.
 
 Seeexecute(PrintStream, InputStream)for more details.- See Also:
- execute(PrintStream, InputStream)
 
- 
executepublic void execute(java.io.PrintStream output, java.io.InputStream input)Starts executing theCLIuntil the current thread is interrupted. When this method is invoked, theCLIstarts writing the title on the specified out stream. Then theCLIwrites a short message to show to the user how to list the available commands. Finally theCLIwrites the command prompt on the out stream and starts listening for new commands on the given in stream.- Parameters:
- output- the out stream on which the user can see CLI messages (can be the standard out- System.out)
- input- the in stream on which the user writes the commands (can be the standard in- System.in)
 
 
-