Class Naftah.NaftahCommand.ShellCommand

java.lang.Object
org.daiitech.naftah.Naftah.NaftahCommand
org.daiitech.naftah.Naftah.NaftahCommand.ShellCommand
Enclosing class:
Naftah.NaftahCommand

private static final class Naftah.NaftahCommand.ShellCommand extends Naftah.NaftahCommand
The 'shell' subcommand that starts the interactive Naftah REPL (Read-Eval-Print Loop).

This command launches an interactive programming environment where users can enter single lines of Naftah code, evaluate them immediately, and see the results. It provides a REPL interface for rapid experimentation, learning, and testing of Naftah scripts.

The REPL supports both English and Arabic commands, allowing users to:

  • Exit the session
  • Display help instructions
  • Reset the session
  • List variables, functions, and implementations
  • Inspect imports
  • Save session state
  • View, sanitize, or purge command history

Example usage:


 naftah shell
 :help                 // display available REPL commands
 :vars                 // list defined variables
 :functions            // list defined functions
 :exit                 // terminate the REPL session
 
See Also:
  • Field Details

    • NAME

      private static final String NAME
      The name of the 'shell' subcommand and the REPL session start timestamp.
      See Also:
    • START_TIME

      private static final Instant START_TIME
      The timestamp marking when the REPL session was started.
  • Constructor Details

    • ShellCommand

      private ShellCommand()
  • Method Details

    • run

      protected void run(Naftah main, boolean bootstrapAsync) throws Exception
      Runs the command.
      Overrides:
      run in class Naftah.NaftahCommand
      Parameters:
      main - the main Naftah instance
      bootstrapAsync - whether to bootstrap asynchronously
      Throws:
      Exception - if any error occurs
    • checkManagementCommands

      private boolean checkManagementCommands(String line, org.jline.reader.History history) throws IOException
      Checks and executes REPL management commands entered by the user.

      This method parses the provided input line and determines if it matches any recognized REPL management command. Supported commands allow the user to:

      • Exit the REPL session (:exit or :خروج)
      • Display the help menu (:help or :مساعدة)
      • Reset the REPL session (:reset or :إعادة_ضبط)
      • List defined variables (:vars or :المتغيرات)
      • List defined functions (:functions or :الدوال)
      • List defined implementations and their functions (:implementations or :السلوكيات)
      • List imported elements (:imports or :الواردات)
      • Save the current session to a snippet file (:save or :حفظ)
      • View the full command history (:history or :الأوامر_المحفوظة)
      • View current session command history (:current_session_history or :الأوامر_المحفوظة_الحالية)
      • Sanitize command history (:sanitize_history or :تنظيف_الأوامر_المحفوظة)
      • Purge the command history (:purge_history or :مسح_الأوامر_المحفوظة)
      • Drop specific variables, functions, implementations, or imports (:drop)

      Commands may be entered in either English or Arabic. Some commands, like :drop, accept additional arguments to specify which elements to remove. When a recognized command is executed, this method performs the corresponding action (e.g., clearing variables, displaying lists, paginating output) and returns true. If the input does not match any known management command, false is returned.

      Parameters:
      line - the input line to check for management commands
      history - the REPL session history used for history-related commands
      Returns:
      true if the input matches and executes a known REPL management command; false otherwise
      Throws:
      IOException - if an I/O error occurs while processing the command
      org.jline.reader.UserInterruptException - if the input corresponds to an exit command (for example ":exit" or ":خروج"), indicating that the user session should be terminated