Using spf13/Cobra for cli flag parsing.
root command has a field marked required:
rootCmd.PersistentFlags().StringVarP(&configFilePath, "config", "c","", "REQUIRED: config file")
rootCmd.MarkPersistentFlagRequired("config")
rootCmd.MarkFlagRequired("config")
However, cobra does not raise an error if it's the root command.
If I add a subcommand and add a required field, .MarkFlagRequired raises an error as expected if the argument is not provided on the command line.
This works for me.
Output
sub command
root command