summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 22:30:42 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 22:30:42 +0200
commit6eaa71ba0d7c0b56853860c2f1eb43096dd928e7 (patch)
treef328cb2bc31dca6524d8bf78c6c4e43d1ffb3cb0
parentbd4750a4094ba8c6cddb6559e4599df2c068ced9 (diff)
Replace global variable with function in internal/repl
-rw-r--r--internal/repl/commands.go6
-rw-r--r--internal/repl/repl.go4
-rw-r--r--internal/repl/repl_completer_test.go2
3 files changed, 7 insertions, 5 deletions
diff --git a/internal/repl/commands.go b/internal/repl/commands.go
index d03672e..2f3a942 100644
--- a/internal/repl/commands.go
+++ b/internal/repl/commands.go
@@ -6,11 +6,13 @@ import (
)
// builtinCommands defines the built-in REPL commands
-var builtinCommands = []string{"help", "clear", "quit", "exit", "rpn", "calc"}
+func builtinCommands() []string {
+ return []string{"help", "clear", "quit", "exit", "rpn", "calc"}
+}
// Commands returns the list of built-in command names supported by the REPL.
func Commands() []string {
- return builtinCommands
+ return builtinCommands()
}
// ExecuteCommand runs a built-in command and returns its output or error
diff --git a/internal/repl/repl.go b/internal/repl/repl.go
index 1b6e249..1870d6c 100644
--- a/internal/repl/repl.go
+++ b/internal/repl/repl.go
@@ -164,7 +164,7 @@ func isBuiltinCommand(input string) (string, bool) {
}
cmd := strings.ToLower(args[0])
- for _, builtin := range builtinCommands {
+ for _, builtin := range builtinCommands() {
if cmd == builtin {
return input, true
}
@@ -237,7 +237,7 @@ func completer(d prompt.Document) []prompt.Suggest {
}
var suggestions []prompt.Suggest
- for _, cmd := range builtinCommands {
+ for _, cmd := range builtinCommands() {
if strings.HasPrefix(strings.ToLower(cmd), strings.ToLower(text)) {
suggestions = append(suggestions, prompt.Suggest{Text: cmd, Description: getCommandDescription(cmd)})
}
diff --git a/internal/repl/repl_completer_test.go b/internal/repl/repl_completer_test.go
index 997d303..861256a 100644
--- a/internal/repl/repl_completer_test.go
+++ b/internal/repl/repl_completer_test.go
@@ -45,7 +45,7 @@ func TestCompleterLogic(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// Simulate the completer logic
var found bool
- for _, cmd := range builtinCommands {
+ for _, cmd := range builtinCommands() {
if strings.HasPrefix(strings.ToLower(cmd), strings.ToLower(tc.text)) {
found = true
break