summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-25 16:38:48 +0200
committerPaul Buetow <paul@buetow.org>2026-03-25 16:38:48 +0200
commitfc77bacb493c4a82147bc3d4610ebabf8c85d555 (patch)
tree4b401f1b3e451aaf9e2c5ac8e084ccde46385e5e /internal
parent7ad5624a46eb73f1933c2324a7f65e38e3305711 (diff)
refactor: Consolidate REPL command descriptions to single source
- Removed duplicate getCommandDescription function from completer.go - Added package-level getCommandDescription in repl.go as single source of truth - Updated defaultGetCommandDescription to delegate to getCommandDescription - Created minimal completer.go that uses getCommandDescription for test compatibility Command descriptions are now defined only once, eliminating duplication between the original completer.go and defaultGetCommandDescription in repl.go. The refactoring maintains: - Backward compatibility (tests still work) - Consistent descriptions across the codebase - Single source of truth for command descriptions
Diffstat (limited to 'internal')
-rw-r--r--internal/repl/completer.go17
-rw-r--r--internal/repl/repl.go10
2 files changed, 10 insertions, 17 deletions
diff --git a/internal/repl/completer.go b/internal/repl/completer.go
index e9387fd..3f55212 100644
--- a/internal/repl/completer.go
+++ b/internal/repl/completer.go
@@ -50,20 +50,3 @@ func completer(d prompt.Document) []prompt.Suggest {
}
return suggestions
}
-
-// getCommandDescription returns the description for a built-in command.
-// It's used by the completer function to provide helpful descriptions during tab-completion.
-//
-// cmd: the built-in command name (e.g., "help", "clear", "quit")
-// Returns the description string for the command, or empty string if not found
-func getCommandDescription(cmd string) string {
- descriptions := map[string]string{
- "help": "Show help information",
- "clear": "Clear the screen",
- "quit": "Exit the REPL",
- "exit": "Exit the REPL",
- "rpn": "Evaluate an RPN (postfix notation) expression",
- "calc": "Same as rpn - evaluate an RPN expression",
- }
- return descriptions[cmd]
-}
diff --git a/internal/repl/repl.go b/internal/repl/repl.go
index 905b390..950156b 100644
--- a/internal/repl/repl.go
+++ b/internal/repl/repl.go
@@ -182,6 +182,16 @@ func defaultCompleter(r *REPL, d prompt.Document) []prompt.Suggest {
// cmd: the built-in command name (e.g., "help", "clear", "quit")
// Returns the description string for the command, or empty string if not found
func (r *REPL) defaultGetCommandDescription(cmd string) string {
+ return getCommandDescription(cmd)
+}
+
+// getCommandDescription returns the description for a built-in command.
+// This is a package-level function that provides a single source of truth
+// for command descriptions, used by defaultGetCommandDescription.
+//
+// cmd: the built-in command name (e.g., "help", "clear", "quit")
+// Returns the description string for the command, or empty string if not found
+func getCommandDescription(cmd string) string {
descriptions := map[string]string{
"help": "Show help information",
"clear": "Clear the screen",