package main import ( "os" gohealthchecks "git.faercol.me/faercol/go-healthchecks" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ Use: "healthchecks-ping", Short: "Client for the healthchecks ping API", Long: ``, } var ( pingHost string checkUUID string pingKey string checkSlug string autoCreate bool ) // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { os.Exit(1) } } func init() { rootCmd.PersistentFlags().StringVar(&pingHost, "host", gohealthchecks.HealthchecksIOPingHost, "healthchecks host to use") rootCmd.PersistentFlags().BoolVar(&autoCreate, "auto-create", false, "auto create check if it does not exist (slug only)") rootCmd.PersistentFlags().StringVar(&checkUUID, "uuid", "", "check UUID") rootCmd.PersistentFlags().StringVar(&pingKey, "ping-key", "", "ping key") rootCmd.PersistentFlags().StringVar(&checkSlug, "slug", "", "check-slug") rootCmd.MarkFlagsRequiredTogether("ping-key", "slug") rootCmd.MarkFlagsMutuallyExclusive("uuid", "slug") rootCmd.MarkFlagsOneRequired("uuid", "slug") }