fix: allow --help with API key
This commit is contained in:
13
main.go
13
main.go
@@ -27,6 +27,12 @@ var rootCmd = &cobra.Command{
|
|||||||
Short: "email is a command line interface for sending emails.",
|
Short: "email is a command line interface for sending emails.",
|
||||||
Long: `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 {
|
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() {
|
if hasStdin() {
|
||||||
b, err := io.ReadAll(os.Stdin)
|
b, err := io.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,13 +88,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user