diff --git a/main.go b/main.go index 9eb772e4..cb6b997e 100644 --- a/main.go +++ b/main.go @@ -37,11 +37,17 @@ func configureRootCommand() *cobra.Command { RunE: run, } + /* + Sensitive flags + default to using envvar value + do not mark as required + manually test for empty value + */ cmd.Flags().StringVarP(&webhookURL, "webhook-url", "w", - "", - "The webhook url to send messages to") + os.Getenv("SLACK_WEBHOOK_URL"), + "The webhook url to send messages to, defaults to value of SLACK_WEBHOOK_URL env variable") cmd.Flags().StringVarP(&channel, "channel", @@ -75,6 +81,11 @@ func run(cmd *cobra.Command, args []string) error { _ = cmd.Help() return errors.New("invalid argument(s) received") } + if webhookURL == "" { + _ = cmd.Help() + return fmt.Errorf("webhook url is empty") + + } if stdin == nil { stdin = os.Stdin }