From 3d055d404dd3de55862860e21515d92f8fb2550d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 23 Mar 2026 22:32:49 +0200 Subject: Replace global variable with function in internal/repl/commands.go --- internal/repl/commands.go | 10 +++++++--- 1 file 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, ", ")) } } -- cgit v1.2.3