fix: allow --help with API key

This commit is contained in:
Maas Lalani 2023-06-15 15:17:22 -04:00
parent bc4cb4caf8
commit 72450a7fc6
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000

13
main.go
View file

@ -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)