-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
area/cobra-commandCore `cobra.Command` implementationsCore `cobra.Command` implementationskind/bugA bug in cobra; unintended behaviorA bug in cobra; unintended behavior
Description
This issue seems to be similar to #1093.
The auto-implemented subcommands (help and completion) don't work when MarkPersistentRequiredFlag() called on root command.
Of course it works if the required flag is specified.
IMHO, these auto-implemented subcommands should be able to work without flags defined by user.
Additionaly, these subcommends should not ignore auto-implement flags like -h, --help (this differs from #1093).
package main
import (
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "mycmd",
}
var subCmd = &cobra.Command{
Use: "subcmd",
Run: func(cmd *cobra.Command, args []string) {},
}
func main() {
rootCmd.PersistentFlags().Bool("required", true, "required")
rootCmd.MarkPersistentFlagRequired("required")
rootCmd.AddCommand(subCmd)
rootCmd.Execute()
}$ go run . help
Error: required flag(s) "required" not set
Usage:
mycmd help [command] [flags]
Flags:
-h, --help help for help
Global Flags:
--required required (default true)Metadata
Metadata
Assignees
Labels
area/cobra-commandCore `cobra.Command` implementationsCore `cobra.Command` implementationskind/bugA bug in cobra; unintended behaviorA bug in cobra; unintended behavior