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},