Class Naftah.NaftahCommand.ShellCommand
- Enclosing class:
- Naftah.NaftahCommand
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumEnum representing the REPL-specific commands supported in the Naftah interactive shell. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe name of the 'shell' subcommand and the REPL session start timestamp.private static final InstantThe timestamp marking when the REPL session was started.Fields inherited from class org.daiitech.naftah.Naftah.NaftahCommand
arguments, enabledCaches -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancheckManagementCommands(String line, org.jline.reader.History history) Checks and executes REPL management commands entered by the user.protected voidRuns the command.
-
Field Details
-
NAME
The name of the 'shell' subcommand and the REPL session start timestamp.- See Also:
-
START_TIME
The timestamp marking when the REPL session was started.
-
-
Constructor Details
-
ShellCommand
private ShellCommand()
-
-
Method Details
-
run
Runs the command.- Overrides:
runin classNaftah.NaftahCommand- Parameters:
main- the main Naftah instancebootstrapAsync- 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 returnstrue. If the input does not match any known management command,falseis returned.- Parameters:
line- the input line to check for management commandshistory- the REPL session history used for history-related commands- Returns:
trueif the input matches and executes a known REPL management command;falseotherwise- Throws:
IOException- if an I/O error occurs while processing the commandorg.jline.reader.UserInterruptException- if the input corresponds to an exit command (for example ":exit" or ":خروج"), indicating that the user session should be terminated
-