Skip to content

Commit

Permalink
fix: don't run preRun for auto command
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jun 14, 2023
1 parent d598898 commit 2f2aef8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ var rootCmd = &cobra.Command{
Version: buildVersion() + "\n\n" + constants.ProjectURL,
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
initLogger()
err := initWorkDir()
if err != nil {
return err
}
err = config.Load(cmd == initCmd)
return err
},
}

func Execute() {
Expand Down Expand Up @@ -82,6 +73,16 @@ func initLogger() {
}
}

func preRun(cmd *cobra.Command, args []string) error {
initLogger()
err := initWorkDir()
if err != nil {
return err
}
err = config.Load(cmd == initCmd)
return err
}

func initCommands() {
cobra.EnableCommandSorting = false

Expand Down Expand Up @@ -115,6 +116,7 @@ func initCommands() {
}
for _, cmd := range commands {
cmd.Flags().SortFlags = false
cmd.PersistentPreRunE = preRun
rootCmd.AddCommand(cmd)
}
rootCmd.InitDefaultHelpCmd()
Expand Down

0 comments on commit 2f2aef8

Please sign in to comment.