diff --git a/Gopkg.lock b/Gopkg.lock index 4d287b8..bdc1304 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -26,10 +26,10 @@ version = "v3.5.1" [[projects]] - branch = "master" name = "github.com/c-bata/go-prompt" packages = ["."] - revision = "c0d9fd4f527efbaa5602586fdb7fbb449c974c2b" + revision = "b5d7d9eae33759a6646cb41768966b593eef18f3" + version = "v0.1.0" [[projects]] branch = "master" @@ -191,13 +191,13 @@ branch = "master" name = "golang.org/x/sys" packages = ["unix","windows"] - revision = "e42485b6e20ae7d2304ec72e535b103ed350cc02" + revision = "c84c1ab9fd18cdd4c23dd021c10f5f46dea95e46" [[projects]] branch = "master" name = "golang.org/x/text" packages = ["internal/gen","internal/triegen","internal/ucd","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable","width"] - revision = "b19bf474d317b857955b12035d2c5acb57ce8b01" + revision = "e56139fd9c5bc7244c76116c68e500765bb6db6b" [[projects]] name = "google.golang.org/appengine" @@ -215,7 +215,7 @@ branch = "v2" name = "gopkg.in/yaml.v2" packages = ["."] - revision = "25c4ec802a7d637f88d584ab26798e94ad14c13b" + revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f" [[projects]] name = "k8s.io/client-go" diff --git a/kube/completer.go b/kube/completer.go index 80e48af..2d9bc0c 100644 --- a/kube/completer.go +++ b/kube/completer.go @@ -6,15 +6,23 @@ import ( "github.com/c-bata/go-prompt" ) -func Completer(s string) []prompt.Suggest { - if s == "" { +func Completer(d prompt.Document) []prompt.Suggest { + if d.TextBeforeCursor() == "" { return []prompt.Suggest{} } - args := strings.Split(s, " ") - l := len(args) + args := strings.Split(d.TextBeforeCursor(), " ") + w := d.GetWordBeforeCursor() - if strings.HasPrefix(args[l-1], "-") { - return optionCompleter(args, strings.HasPrefix(args[l-1], "--")) + // If PIPE is in text before the cursor, returns empty suggestions. + for i := range args { + if args[i] == "|" { + return []prompt.Suggest{} + } + } + + // If word before the cursor starts with "-", returns CLI flag options. + if strings.HasPrefix(w, "-") { + return optionCompleter(args, strings.HasPrefix(w, "--")) } return argumentsCompleter(excludeOptions(args)) diff --git a/main.go b/main.go index 9a5fa65..3acdf26 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ var ( ) func main() { + fmt.Printf("kube-prompt %s (rev-%s)\n", version, revision) defer fmt.Println("Goodbye!") p := prompt.New( kube.Executor,