Package javax0.repl

Class 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 alias
      Repl 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 the
      void 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Repl

        public Repl()
        Create a new object that already has the built-in commands configured.
    • 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
      • 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 use
        command - 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 types exit. A true 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 signal true. If the return value of the function is false then the application will not exit unless the user specified the confirm=yes parameter. If this parameter is specified the function is still consulted but its veto (a.k.a. the returned false 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 interface java.lang.Runnable