Skip to content

Commit

Permalink
make sure all output goes to stdout, except printing yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Nov 8, 2023
1 parent fdbb40d commit 806630e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ var rootCmd = &cobra.Command{
// Execute the top level command
func Execute() {
if err := rootCmd.Execute(); err != nil {
// fmt.Println(radixCLIError)
// fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Expand Down
20 changes: 8 additions & 12 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,36 @@ var validateCmd = &cobra.Command{
}

if _, err := os.Stat(radixconfig); errors.Is(err, os.ErrNotExist) {
return errors.New(fmt.Sprintf("RadixConfig file note found: %s", radixconfig))
return fmt.Errorf("RadixConfig file note found: %s", radixconfig)
}

ra, err := utils.GetRadixApplicationFromFile(radixconfig)
if err != nil {
fmt.Printf("Syntax error in RadixConfig file:\n\n")
fmt.Println(err)
return errors.New("RadixConfig is invalid")
return errors.Wrap(err, "RadixConfig is invalid")
}

if printfile {
printRA(ra)
}

err = radixvalidators.IsRadixApplicationValid(ra)
if err == nil {
fmt.Println("RadixConfig is valid")
return nil
if err != nil {
return fmt.Errorf("RadixConfig is invalid:\n%v", err)
}

fmt.Println(err)

return errors.New("RadixConfig is invalid")
fmt.Fprintln(os.Stderr, "RadixConfig is valid")
return nil
},
}

func printRA(ra *radixv1.RadixApplication) {
b, err := yaml.Marshal(ra)
if err != nil {
fmt.Println(err)
fmt.Fprint(os.Stderr, err)
return
}

fmt.Printf("%s\n", b)
fmt.Fprintf(os.Stdout, "%s\n", b)
}

func init() {
Expand Down

0 comments on commit 806630e

Please sign in to comment.