Package javax0.repl
Class Repl
- java.lang.Object
-
- javax0.repl.Repl
-
- All Implemented Interfaces:
java.lang.Runnable
public class Repl extends java.lang.Object implements java.lang.Runnable
-
-
Constructor Summary
Constructors Constructor Description Repl()
Create a new object that already has the built-in commands configured.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Repl
alias(java.lang.String alias, java.lang.String command)
Define a new aliasRepl
allowExit(java.util.function.Function<CommandEnvironment,java.lang.Boolean> allowExit)
Define an allow exit function.Repl
args(java.lang.String[] args)
Pass the arguments to the application from the OS command line.Repl
command(CommandDefinitionBuilder.CommandDefinitionBuilderReady builder)
Define a command.Repl
debug()
Switch the Repl into debug mode.Repl
prompt(java.lang.String prompt)
Define the prompt that th euser will see in thevoid
run()
Run the application.Repl
startup(java.lang.String startupFile)
Define the name of the startup file that is executed when the applicatoin starts to run.Repl
stateReporter(java.util.function.Consumer<CommandEnvironment> stateReporter)
Define a command, which is started after each configured command execution.Repl
title(java.lang.String title)
Provide a title for the application.
-
-
-
Method Detail
-
debug
public Repl debug()
Switch the Repl into debug mode. In this mode the exceptions are printed to the screen including the stack trace. In non-debug mode only a short information is printed about exceptions that happen during command execution but the code details are not displayed.- Returns:
- this
-
command
public Repl command(CommandDefinitionBuilder.CommandDefinitionBuilderReady builder)
Define a command. The command has to be specified in the form of a builder which is implemented in theCommandDefinitionBuilder
and which implements fluent API to ease the definition of commands. Note that the finalCommandDefinitionBuilder.CommandDefinitionBuilderReady.build()
method should not be invoked. It will be invoked here by the method.- Parameters:
builder
- the builder that is ready for the building.- Returns:
- this
-
args
public Repl args(java.lang.String[] args)
Pass the arguments to the application from the OS command line.- Parameters:
args
- the arguments that the application should see as it was passed on the command line by the user as the repl application was started- Returns:
- this
-
alias
public Repl alias(java.lang.String alias, java.lang.String command)
Define a new alias- Parameters:
alias
- the name of the alias the user can later usecommand
- the command that the alias means- Returns:
- this
-
stateReporter
public Repl stateReporter(java.util.function.Consumer<CommandEnvironment> stateReporter)
Define a command, which is started after each configured command execution. This command can use the environment console to output information about the state of the application.- Parameters:
stateReporter
- the command implementation- Returns:
- this
-
allowExit
public Repl allowExit(java.util.function.Function<CommandEnvironment,java.lang.Boolean> allowExit)
Define an allow exit function. The allow exit function is consulted by the repl application when the user typesexit
. Atrue
value from the function will signal the application that there is no problem exiting from the application. The function should veto the exiting in case there is some unsaved data. The function may also save the data and then signaltrue
. If the return value of the function isfalse
then the application will not exit unless the user specified theconfirm=yes
parameter. If this parameter is specified the function is still consulted but its veto (a.k.a. the returnedfalse
value) is ignored and the application will exit.- Parameters:
allowExit
- the function that implements the unsaved resource checking and vetoing- Returns:
- this
-
title
public Repl title(java.lang.String title)
Provide a title for the application. It will be printed when the application starts.- Parameters:
title
- the tile that is printed- Returns:
- this
-
prompt
public Repl prompt(java.lang.String prompt)
Define the prompt that th euser will see in the- Parameters:
prompt
-- Returns:
-
startup
public Repl startup(java.lang.String startupFile)
Define the name of the startup file that is executed when the applicatoin starts to run.- Parameters:
startupFile
- the name of the file- Returns:
- this
-
run
public void run()
Run the application.- Specified by:
run
in interfacejava.lang.Runnable
-
-