You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt""os""github.com/spf13/cobra"
)
varrootCmd=&cobra.Command{
Use: "app",
Short: "A sample CLI program",
Long: "A sample CLI program that demonstrates intelligent command suggestions",
Run: func(cmd*cobra.Command, args []string) {
fmt.Println("Hello, world!")
},
}
varserverCmd=&cobra.Command{
Use: "server",
Short: "Server top-level",
Long: "This is a top-level server command",
Run: func(cmd*cobra.Command, args []string) {},
}
varstartCmd=&cobra.Command{
Use: "start",
Short: "Start the server",
Long: "Start the server and listen for incoming requests",
Run: func(cmd*cobra.Command, args []string) {
fmt.Println("Starting the server...")
},
}
funcinit() {
rootCmd.AddCommand(serverCmd)
serverCmd.AddCommand(startCmd)
}
funcmain() {
iferr:=rootCmd.Execute(); err!=nil {
fmt.Println(err)
os.Exit(1)
}
}
Command suggestions for misspelled command names work fine at the top-level.
$ go run main.go serve
Error: unknown command"serve"for"app"
Did you mean this?
server
Run 'app --help'for usage.
unknown command"serve"for"app"
Did you mean this?
server
exit status 1
However, it fails at the nested command level.
$ go run main.go server stat
Is this not supported?
Also, when I have these commands separated into individual go files (root.go, server.go, and stat.go etc), nested command suggestions do not even work.
$ go run main.go serve
Error: unknown command"serve"for"app"
Did you mean this?
server
Run 'app --help'for usage.
exit status 1
$ go run main.go server stat
This is the top-level server command
Usage:
app server [command]
Available Commands:
start Stars a server
Flags:
-h, --help helpfor server
Use "app server [command] --help"for more information about a command.
The text was updated successfully, but these errors were encountered:
Consider the following example.
Command suggestions for misspelled command names work fine at the top-level.
However, it fails at the nested command level.
Is this not supported?
Also, when I have these commands separated into individual go files (root.go, server.go, and stat.go etc), nested command suggestions do not even work.
The text was updated successfully, but these errors were encountered: