From 155d9d79ae992387e01bc6e99fbd6405031a639a Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Mon, 9 Feb 2026 20:28:42 +0100 Subject: [PATCH] refine suggestions a bit --- pkg/cli/repl/suggestions.go | 47 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index c62e499..ba79385 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -37,6 +37,7 @@ var createFlags = []prompt.Suggest{ {Text: "--priority", Description: "Issue priority (0-5)"}, } +// updateFlags is a list of prompt suggestions for the update command flags. var updateFlags = []prompt.Suggest{ {Text: "--title", Description: "New issue title"}, {Text: "--desc", Description: "New issue description"}, @@ -88,6 +89,18 @@ var isIDCommand = map[string]bool{ "get": true, "read": true, "close": true, + "update": true, + "edit": true, +} + +var commandFlags = map[string][]prompt.Suggest{ + "create": createFlags, + "add": createFlags, + "update": updateFlags, + "edit": updateFlags, + "list": listFlags, + "ls": listFlags, + "search": listFlags, } // commandSuggestions returns a list of prompt suggestions based on the current input words. @@ -106,39 +119,15 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(values, lastWord) } + flags := commandFlags[cmd] + if isIDCommand[cmd] { - // For ID-oriented commands, pass the current partial argument (lastWord) - // so issueIDSuggestions can distinguish between completing the command - // name and completing the ID itself. - return issueIDSuggestions(lastWord, len(words) >= 2) - } - - // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided - if cmd == "update" || cmd == "edit" { - if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { - // ID already provided (trailing space) or typing a flag -> suggest update flags - flags := updateFlags - if lastWord == "" { - return flags - } - return filterByPrefix(flags, lastWord) + if len(words) < 2 && !strings.HasPrefix(lastWord, "-") { + return issueIDSuggestions(lastWord, true) } - return issueIDSuggestions(lastWord, len(words) >= 2) + return filterByPrefix(flags, lastWord) } - var flags []prompt.Suggest - switch cmd { - case "create", "add": - flags = createFlags - case "list", "ls", "search": - flags = listFlags - default: - return nil - } - - if lastWord == "" { - return flags - } return filterByPrefix(flags, lastWord) }