fix: handle both resend and smtp set up together (#28)
* fix: handle both resend and smtp set up together closes #27 * fix: error header * fix: error messaging --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
This commit is contained in:
committed by
GitHub
parent
ee206143a8
commit
fca3852910
12
main.go
12
main.go
@@ -76,6 +76,8 @@ var rootCmd = &cobra.Command{
|
|||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
var deliveryMethod DeliveryMethod
|
var deliveryMethod DeliveryMethod
|
||||||
switch {
|
switch {
|
||||||
|
case resendAPIKey != "" && smtpUsername != "" && smtpPassword != "":
|
||||||
|
deliveryMethod = Unknown
|
||||||
case resendAPIKey != "":
|
case resendAPIKey != "":
|
||||||
deliveryMethod = Resend
|
deliveryMethod = Resend
|
||||||
case smtpUsername != "" && smtpPassword != "":
|
case smtpUsername != "" && smtpPassword != "":
|
||||||
@@ -83,12 +85,20 @@ var rootCmd = &cobra.Command{
|
|||||||
from = smtpUsername
|
from = smtpUsername
|
||||||
}
|
}
|
||||||
|
|
||||||
if deliveryMethod == None {
|
switch deliveryMethod {
|
||||||
|
case None:
|
||||||
fmt.Printf("\n %s %s %s\n\n", errorHeaderStyle.String(), inlineCodeStyle.Render(ResendAPIKey), "environment variable is required.")
|
fmt.Printf("\n %s %s %s\n\n", errorHeaderStyle.String(), inlineCodeStyle.Render(ResendAPIKey), "environment variable is required.")
|
||||||
fmt.Printf(" %s %s\n\n", commentStyle.Render("You can grab one at"), linkStyle.Render("https://resend.com/api-keys"))
|
fmt.Printf(" %s %s\n\n", commentStyle.Render("You can grab one at"), linkStyle.Render("https://resend.com/api-keys"))
|
||||||
cmd.SilenceUsage = true
|
cmd.SilenceUsage = true
|
||||||
cmd.SilenceErrors = true
|
cmd.SilenceErrors = true
|
||||||
return errors.New("missing required environment variable")
|
return errors.New("missing required environment variable")
|
||||||
|
case Unknown:
|
||||||
|
fmt.Printf("\n %s Unknown delivery method.\n", errorHeaderStyle.String())
|
||||||
|
fmt.Printf("\n You have set both %s and %s delivery methods.", inlineCodeStyle.Render(ResendAPIKey), inlineCodeStyle.Render("POP_SMPT_*"))
|
||||||
|
fmt.Printf("\n Set only one of these environment variables.\n\n")
|
||||||
|
cmd.SilenceUsage = true
|
||||||
|
cmd.SilenceErrors = true
|
||||||
|
return errors.New("unknown delivery method")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasStdin() {
|
if hasStdin() {
|
||||||
|
|||||||
3
model.go
3
model.go
@@ -41,6 +41,9 @@ const (
|
|||||||
Resend
|
Resend
|
||||||
// SMTP uses an SMTP server to send an email.
|
// SMTP uses an SMTP server to send an email.
|
||||||
SMTP
|
SMTP
|
||||||
|
// Unknown is set when the user has not chosen a single delivery method.
|
||||||
|
// i.e. multiple delivery methods are set.
|
||||||
|
Unknown
|
||||||
)
|
)
|
||||||
|
|
||||||
// Model is Pop's application model.
|
// Model is Pop's application model.
|
||||||
|
|||||||
Reference in New Issue
Block a user