From fd5c13f7ed2e9a3e3a82fa6a4c6ffe649f3f32f2 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Sun, 7 May 2017 07:59:42 +0300 Subject: [PATCH] Remove Name from Command struct --- command.go | 7 ------- gocomplete/complete.go | 3 +-- readme.md | 6 ++---- run.go | 7 +++++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/command.go b/command.go index b658af3..f2b8354 100644 --- a/command.go +++ b/command.go @@ -4,13 +4,6 @@ package complete // It holds the data that enables auto completion of a given typed command line // Command can also be a sub command. type Command struct { - // Name is the name of command, - // IMPORTANT: For root command - it must be the same name as the program - // that the auto complete completes. So if the auto complete - // completes the 'go' command, Name must be equal to "go". - // It is optional for sub commands. - Name string - // Sub is map of sub commands of the current command // The key refer to the sub command name, and the value is it's // Command descriptive struct. diff --git a/gocomplete/complete.go b/gocomplete/complete.go index bdeecd1..4eab6a5 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -165,7 +165,6 @@ func main() { } gogo := complete.Command{ - Name: "go", Sub: complete.Commands{ "build": build, "install": build, // install and build have the same flags @@ -188,5 +187,5 @@ func main() { }, } - complete.Run(gogo) + complete.Run("go", gogo) } diff --git a/readme.md b/readme.md index 62ce6af..5ad2e71 100644 --- a/readme.md +++ b/readme.md @@ -54,9 +54,6 @@ func main() { // to complete. run := complete.Command{ - // Name must be exactly as the binary that we want to complete - Name: "run", - // Sub defines a list of sub commands of the program, // this is recursive, since every command is of type command also. Sub: complete.Commands{ @@ -88,6 +85,7 @@ func main() { // run the command completion, as part of the main() function. // this triggers the autocompletion when needed. - complete.Run(run) + // name must be exactly as the binary that we want to complete. + complete.Run("run", run) } ``` diff --git a/run.go b/run.go index 90d0df4..5d9706f 100644 --- a/run.go +++ b/run.go @@ -20,10 +20,13 @@ const ( // Run get a command, get the typed arguments from environment // variable, and print out the complete options -func Run(c Command) { +// name is the name of command we want to auto complete. +// IMPORTANT: it must be the same name - if the auto complete +// completes the 'go' command, name must be equal to "go". +func Run(name string, c Command) { args, ok := getLine() if !ok { - cmd.Run(c.Name) + cmd.Run(name) return } Log("Completing args: %s", args)