Skip to content

Commit

Permalink
Return exit code 1 on failure and silence redundant cobra errors (#86)
Browse files Browse the repository at this point in the history
* Return Exit Code 1 on Failure

Previously, the code returned exit code 0 even when the template
generation failed. Now, if an error occurs, the program will return
exit code 1.

* Silence Errors from Cobra Execution

Previously, Cobra was printing non-formatted errors. However, we
already log these errors via zap. This fix silences Cobra from printing
redundant logs.
  • Loading branch information
gcs278 committed Jul 25, 2024
1 parent a178c7b commit 9e0eec8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ var args = config.Flags{}

func main() {
cmd := cobra.Command{
Use: "crd-ref-docs",
Short: "Generate CRD reference documentation",
SilenceUsage: true,
Version: version(),
RunE: doRun,
Use: "crd-ref-docs",
Short: "Generate CRD reference documentation",
SilenceUsage: true,
SilenceErrors: true,
Version: version(),
RunE: doRun,
}

cmd.SetVersionTemplate("{{ .Version }}\n")
Expand All @@ -52,7 +53,9 @@ func main() {
cmd.Flags().StringVar(&args.OutputMode, "output-mode", "single", "Output mode to generate a single file or one file per group ('group' or 'single')")
cmd.Flags().IntVar(&args.MaxDepth, "max-depth", 10, "Maximum recursion level for type discovery")

cmd.Execute()
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}

func doRun(_ *cobra.Command, _ []string) error {
Expand Down

0 comments on commit 9e0eec8

Please sign in to comment.