summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 22:32:49 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 22:32:49 +0200
commit3d055d404dd3de55862860e21515d92f8fb2550d (patch)
tree0a0c597513dd92442826ac752e86d63032eb29f3
parent46eb72c79728dcc1147b9c814cbb55181afd0f4f (diff)
Replace global variable with function in internal/repl/commands.go
-rw-r--r--internal/repl/commands.go10
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, ", "))
}
}