From 67a637f7beb484fcbde2690ccc9f50eaf483cef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cm=C3=BCt=20=C3=96zalp?= <54961032+uozalp@users.noreply.github.com> Date: Wed, 20 Aug 2025 16:46:50 +0200 Subject: [PATCH] fix: update SuggestSubCommand to pass command context for suggestions (#3516) --- internal/view/cmd/helpers.go | 10 +++++----- internal/view/cmd/helpers_test.go | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/view/cmd/helpers.go b/internal/view/cmd/helpers.go index 13637f91..2c0065ec 100644 --- a/internal/view/cmd/helpers.go +++ b/internal/view/cmd/helpers.go @@ -58,11 +58,11 @@ func SuggestSubCommand(command string, namespaces client.NamespaceNames, context if !ok { return nil } - suggests = completeCtx(n, contexts) + suggests = completeCtx(command, n, contexts) case p.HasNS(): if n, ok := p.HasContext(); ok { - suggests = completeCtx(n, contexts) + suggests = completeCtx(command, n, contexts) } if len(suggests) > 0 { break @@ -76,7 +76,7 @@ func SuggestSubCommand(command string, namespaces client.NamespaceNames, context default: if n, ok := p.HasContext(); ok { - suggests = completeCtx(n, contexts) + suggests = completeCtx(command, n, contexts) } } slices.Sort(suggests) @@ -99,11 +99,11 @@ func completeNS(s string, nn client.NamespaceNames) []string { return suggests } -func completeCtx(s string, contexts []string) []string { +func completeCtx(command, s string, contexts []string) []string { var suggests []string for _, ctxName := range contexts { if suggest, ok := ShouldAddSuggest(s, ctxName); ok { - if s == "" { + if s == "" && !strings.HasSuffix(command, " ") { suggests = append(suggests, " "+suggest) continue } diff --git a/internal/view/cmd/helpers_test.go b/internal/view/cmd/helpers_test.go index 204bbe67..195c07d7 100644 --- a/internal/view/cmd/helpers_test.go +++ b/internal/view/cmd/helpers_test.go @@ -77,6 +77,8 @@ func TestSuggestSubCommand(t *testing.T) { {Command: "ctx p", Suggestions: []string{"re", "rod"}}, {Command: "ctx p", Suggestions: []string{"re", "rod"}}, {Command: "ctx pr", Suggestions: []string{"e", "od"}}, + {Command: "ctx", Suggestions: []string{" develop", " pre", " prod", " test"}}, + {Command: "ctx ", Suggestions: []string{"develop", "pre", "prod", "test"}}, {Command: "context d", Suggestions: []string{"evelop"}}, {Command: "contexts t", Suggestions: []string{"est"}}, {Command: "po ", Suggestions: nil},