diff --git a/main.go b/main.go index f9e7e03..dee217a 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,12 @@ var rootCmd = &cobra.Command{ Short: "email is a command line interface for sending emails.", Long: `email is a command line interface for sending emails.`, RunE: func(cmd *cobra.Command, args []string) error { + if os.Getenv(RESEND_API_KEY) == "" { + fmt.Printf("\n %s %s %s\n\n", errorHeaderStyle.String(), inlineCodeStyle.Render(RESEND_API_KEY), "environment variable is required.") + fmt.Printf(" %s %s\n\n", commentStyle.Render("You can grab one at"), linkStyle.Render("https://resend.com")) + os.Exit(1) + } + if hasStdin() { b, err := io.ReadAll(os.Stdin) if err != nil { @@ -82,13 +88,6 @@ func init() { } func main() { - key := os.Getenv(RESEND_API_KEY) - if key == "" { - fmt.Printf("\n %s %s %s\n\n", errorHeaderStyle.String(), inlineCodeStyle.Render(RESEND_API_KEY), "environment variable is required.") - fmt.Printf(" %s %s\n\n", commentStyle.Render("You can grab one at"), linkStyle.Render("https://resend.com")) - os.Exit(1) - } - err := rootCmd.Execute() if err != nil { os.Exit(1)