-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subcommand Group | panic: Group id 'Group1' is not defined for subcommand 'app1 sub1' #1831
Comments
Hi, Your advice regarding the issue is appreciated Thanks |
Same here. It's not obvious where the Groups need be added in order to be specified on the child command? /cc @aawsome @marckhouzam |
The As both are in the EDIT: I think you renamed your real subcommand which started with a letter lower than So, to solve your problem, either rename your files such that the file name of the go file defining the subcommand is lexical larger than the file name of the go file defining the root command. Another alternative is to change |
Thanks for the explanation. This is a bit unfortunate from usability perspective as it introduces coupling between otherwise independent parts (except for being aware that there is a Update I would suggest to make the |
Thank @aawsome for your answers and the solutions. I would've never guessed it from
The alternative solution works just fine for me
func init() {
cobra.EnableCaseInsensitive = true
cobra.EnableCommandSorting = false
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.Flags().SortFlags = false
rootCmd.PersistentFlags().SortFlags = false
rootCmd.AddGroup(&cobra.Group{ID: "Group1", Title: "Group1 Subcommands:"})
initSub1()
initSub2()
initSub3()
}
var sub1Cmd = &cobra.Command{
Use: "sub1",
GroupID: "Group1",
Aliases: []string{"1"},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Hiii")
},
}
func initSub1() {
rootCmd.AddCommand(sub1Cmd)
sub1Cmd.Flags().SortFlags = false
sub1Cmd.Flags().StringP("ipaddress", "i", "0.0.0.0", "IP address to listen to")
} I also agree with @andig regarding the inconvenience usability of this approach Thank you all |
@KINGSABRI could you kindly keep this open for the usability aspect? Having to implement this like you just did is really bad. |
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes #1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Much appreciated, thank you! |
Fixes spf13#1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]>
Fixes #1831 By moving the check for help group existence to "ExecuteC()" we no longer need groups to be added before AddCommand() is called. This provides more flexibility to developers and works better with the use of "init()" for command creation. Signed-off-by: Marc Khouzam <[email protected]> Signed-off-by: Marc Khouzam <[email protected]> Co-authored-by: Marc Khouzam <[email protected]>
Hi everyone
I'm trying to implement the subcommand group feature introduced in v[v1.6.0]. I followed the test code
/app1/cmd/root.go
/app1/cmd/sub1.go
When I run the app I get
Q\ is there any complex example that wrapup all cobra's features?
The text was updated successfully, but these errors were encountered: