From fc77bacb493c4a82147bc3d4610ebabf8c85d555 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 25 Mar 2026 16:38:48 +0200 Subject: 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 --- internal/repl/completer.go | 17 ----------------- internal/repl/repl.go | 10 ++++++++++ 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", -- cgit v1.2.3