From 37f5b4c92c33848ceebdd9766ab126603fc877c0 Mon Sep 17 00:00:00 2001 From: c-bata Date: Sat, 2 Nov 2019 23:26:11 +0900 Subject: [PATCH] Support container suggestions on some commands --- kube/completer.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/kube/completer.go b/kube/completer.go index d72e5a4..50d4c82 100644 --- a/kube/completer.go +++ b/kube/completer.go @@ -136,21 +136,30 @@ func (c *Completer) completeOptionArguments(d prompt.Document) ([]prompt.Suggest if !found { return []prompt.Suggest{}, false } + + // namespace + if option == "-n" || option == "--namespace" { + return prompt.FilterHasPrefix( + getNameSpaceSuggestions(c.namespaceList), + d.GetWordBeforeCursor(), + true, + ), true + } + + // filename switch cmd { case "get", "describe", "create", "delete", "replace", "patch", "edit", "apply", "expose", "rolling-update", "rollout", - "label", "annotate", "scale", "convert", "autoscale", "top", "logs": - switch option { - case "-f", "--filename": + "label", "annotate", "scale", "convert", "autoscale", "top": + if option == "-f" || option == "--filename" { return yamlFileCompleter.Complete(d), true - case "-n", "--namespace": - return prompt.FilterHasPrefix( - getNameSpaceSuggestions(c.namespaceList), - d.GetWordBeforeCursor(), - true, - ), true - case "-c", "--container": + } + } + // container + switch cmd { + case "exec", "logs", "run", "attach", "port-forward", "cp": + if option == "-c" || option == "--container" { cmdArgs := getCommandArgs(d) var suggestions []prompt.Suggest if cmdArgs == nil || len(cmdArgs) < 2 {