Remove Name from Command struct
This commit is contained in:
parent
c94813be30
commit
fd5c13f7ed
|
@ -4,13 +4,6 @@ package complete
|
||||||
// It holds the data that enables auto completion of a given typed command line
|
// It holds the data that enables auto completion of a given typed command line
|
||||||
// Command can also be a sub command.
|
// Command can also be a sub command.
|
||||||
type Command struct {
|
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
|
// Sub is map of sub commands of the current command
|
||||||
// The key refer to the sub command name, and the value is it's
|
// The key refer to the sub command name, and the value is it's
|
||||||
// Command descriptive struct.
|
// Command descriptive struct.
|
||||||
|
|
|
@ -165,7 +165,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gogo := complete.Command{
|
gogo := complete.Command{
|
||||||
Name: "go",
|
|
||||||
Sub: complete.Commands{
|
Sub: complete.Commands{
|
||||||
"build": build,
|
"build": build,
|
||||||
"install": build, // install and build have the same flags
|
"install": build, // install and build have the same flags
|
||||||
|
@ -188,5 +187,5 @@ func main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
complete.Run(gogo)
|
complete.Run("go", gogo)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,6 @@ func main() {
|
||||||
// to complete.
|
// to complete.
|
||||||
run := complete.Command{
|
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,
|
// Sub defines a list of sub commands of the program,
|
||||||
// this is recursive, since every command is of type command also.
|
// this is recursive, since every command is of type command also.
|
||||||
Sub: complete.Commands{
|
Sub: complete.Commands{
|
||||||
|
@ -88,6 +85,7 @@ func main() {
|
||||||
|
|
||||||
// run the command completion, as part of the main() function.
|
// run the command completion, as part of the main() function.
|
||||||
// this triggers the autocompletion when needed.
|
// 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
7
run.go
|
@ -20,10 +20,13 @@ const (
|
||||||
|
|
||||||
// Run get a command, get the typed arguments from environment
|
// Run get a command, get the typed arguments from environment
|
||||||
// variable, and print out the complete options
|
// 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()
|
args, ok := getLine()
|
||||||
if !ok {
|
if !ok {
|
||||||
cmd.Run(c.Name)
|
cmd.Run(name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Log("Completing args: %s", args)
|
Log("Completing args: %s", args)
|
||||||
|
|
Loading…
Reference in New Issue