diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-23 22:32:49 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-23 22:32:49 +0200 |
| commit | 3d055d404dd3de55862860e21515d92f8fb2550d (patch) | |
| tree | 0a0c597513dd92442826ac752e86d63032eb29f3 | |
| parent | 46eb72c79728dcc1147b9c814cbb55181afd0f4f (diff) | |
Replace global variable with function in internal/repl/commands.go
| -rw-r--r-- | internal/repl/commands.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/repl/commands.go b/internal/repl/commands.go index 2f3a942..ee8acc8 100644 --- a/internal/repl/commands.go +++ b/internal/repl/commands.go @@ -5,9 +5,13 @@ import ( "strings" ) -// builtinCommands defines the built-in REPL commands +// builtinCommandsList is the list of built-in REPL commands. +// It's exposed as a variable to allow for dependency injection in tests. +var builtinCommandsList = []string{"help", "clear", "quit", "exit", "rpn", "calc"} + +// builtinCommands returns the list of built-in commands. func builtinCommands() []string { - return []string{"help", "clear", "quit", "exit", "rpn", "calc"} + return builtinCommandsList } // Commands returns the list of built-in command names supported by the REPL. @@ -33,7 +37,7 @@ func ExecuteCommand(cmd string) (string, error) { // rpn/calc commands are handled in executor(), not here return "", nil default: - return "", fmt.Errorf("unknown command: %s. Available commands: help, clear, quit, exit, rpn, calc", args[0]) + return "", fmt.Errorf("unknown command: %s. Available commands: %s", args[0], strings.Join(builtinCommandsList, ", ")) } } |
