Skip to content

Commit

Permalink
refactor: for usage errors, show help / for operational errors show j…
Browse files Browse the repository at this point in the history
…son error.

Signed-off-by: ianhundere <138915+ianhundere@users.noreply.github.com>
  • Loading branch information
ianhundere committed Jan 23, 2025
1 parent 513b93b commit d919c1c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/certificate_maker/certificate_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func init() {
}

func runCreate(_ *cobra.Command, _ []string) error {
defer func() { rootCmd.SilenceUsage = true }()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

Expand Down Expand Up @@ -187,7 +188,12 @@ func runCreate(_ *cobra.Command, _ []string) error {
}

func main() {
rootCmd.SilenceErrors = true
if err := rootCmd.Execute(); err != nil {
log.Logger.Fatal("Command failed", zap.Error(err))
if rootCmd.SilenceUsage {
log.Logger.Fatal("Command failed", zap.Error(err))
} else {
os.Exit(1)
}
}
}

0 comments on commit d919c1c

Please sign in to comment.