Remove Name from Command struct

This commit is contained in:
Eyal Posener 2017-05-07 07:59:42 +03:00
parent c94813be30
commit fd5c13f7ed
4 changed files with 8 additions and 15 deletions

View File

@ -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.

View File

@ -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)
}

View File

@ -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)
}
```

7
run.go
View File

@ -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)