go-healthchecks/cmd/root.go

45 lines
1.3 KiB
Go
Raw Permalink Normal View History

2024-10-02 13:26:14 +00:00
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
2024-10-02 14:11:24 +00:00
runID string
2024-10-02 13:26:14 +00:00
)
// 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)")
2024-10-02 14:11:24 +00:00
rootCmd.PersistentFlags().StringVar(&runID, "run-id", "", "Optional run-id to identify the job")
2024-10-02 13:26:14 +00:00
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")
}