diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-11 21:50:15 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-11 21:50:15 +0300 |
| commit | b315ebbcd92e58249c6ed8f04217ef7adcdde5d5 (patch) | |
| tree | d264b595dd2215523ecd1f50540342a3697b612b /internal/repl/commands.go | |
| parent | 8dbe047feaae419d9a5bdc34dfe9153e6704fd7f (diff) | |
more on this
Diffstat (limited to 'internal/repl/commands.go')
| -rw-r--r-- | internal/repl/commands.go | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/internal/repl/commands.go b/internal/repl/commands.go index 841265b..3bdcde5 100644 --- a/internal/repl/commands.go +++ b/internal/repl/commands.go @@ -13,20 +13,12 @@ import ( // Commands: help, clear, quit, exit, rpn, calc, rat var builtinCommandsList = []string{"help", "clear", "quit", "exit", "rpn", "calc", "rat"} -// builtinCommands returns the list of built-in commands. -// This is a package-level wrapper for backward compatibility. -// -// Returns a slice of built-in command names -func builtinCommands() []string { - return builtinCommandsList -} - // Commands returns the list of built-in command names supported by the REPL. // This is a public function that exposes the built-in command list. // // Returns a slice of built-in command names (e.g., "help", "clear", "quit") func Commands() []string { - return builtinCommands() + return builtinCommandsList } // ExecuteCommand runs a built-in command and returns its output or error. @@ -144,3 +136,24 @@ func cmdQuit() error { fmt.Println("Goodbye!") return nil } + +// isBuiltinCommand checks if input starts with a built-in command. +// It performs case-insensitive matching against known built-in commands. +// +// input: the command string to check +// Returns the input string and true if it starts with a built-in command, +// or empty string and false otherwise +func isBuiltinCommand(input string) (string, bool) { + args := strings.Fields(input) + if len(args) == 0 { + return "", false + } + + cmd := strings.ToLower(args[0]) + for _, builtin := range builtinCommandsList { + if cmd == builtin { + return input, true + } + } + return "", false +} |
