Skip to content

Commit 2cd3444

Browse files
committed
Fix help for sub-commands
1 parent 3671df2 commit 2cd3444

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

cmd/root.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ var RootCmd = &cobra.Command{
3030
// Execute adds all child commands to the root command sets flags appropriately.
3131
// This is called by main.main(). It only needs to happen once to the rootCmd.
3232
func Execute() {
33-
helpFunc := RootCmd.HelpFunc()
34-
RootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
35-
initVerbose()
36-
CheckUpdate()
37-
helpFunc(cmd, args)
38-
})
33+
if !verbose {
34+
log.SetOutput(ioutil.Discard)
35+
}
36+
CheckUpdate()
3937
if err := RootCmd.Execute(); err != nil {
4038
fmt.Println(err)
4139
os.Exit(-1)
@@ -44,8 +42,6 @@ func Execute() {
4442

4543
func init() {
4644
cobra.OnInitialize(initConfig)
47-
cobra.OnInitialize(initVerbose)
48-
cobra.OnInitialize(CheckUpdate)
4945

5046
// Here you will define your flags and configuration settings.
5147
// Cobra supports Persistent Flags, which, if defined here,
@@ -81,9 +77,3 @@ func initConfig() {
8177
fmt.Println("Using config file:", viper.ConfigFileUsed())
8278
}
8379
}
84-
85-
func initVerbose() {
86-
if !verbose {
87-
log.SetOutput(ioutil.Discard)
88-
}
89-
}

0 commit comments

Comments
 (0)