summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--command.go7
-rw-r--r--gocomplete/complete.go3
-rw-r--r--readme.md6
-rw-r--r--run.go7
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)