package main import ( "fmt" "os" "strconv" gohealthchecks "git.faercol.me/faercol/go-healthchecks" "github.com/spf13/cobra" ) var returncodeCmd = &cobra.Command{ Use: "returncode ", Short: "Notify specific returncode for the check", Long: ``, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { check := parseCheckFlags() returncode, err := strconv.Atoi(args[0]) if err != nil { failf("Invalid value for returncode: %s\n", err) } clt := gohealthchecks.NewPingClient(pingHost) err = clt.ReportExitCode(cmd.Context(), check, returncode) if err != nil { failf("Failed to send log: %s\n", err) } else { fmt.Println("Log sent") os.Exit(0) } }, } func init() { rootCmd.AddCommand(returncodeCmd) }