feat: convert markdown to html

This commit is contained in:
Maas Lalani
2023-06-15 10:30:20 -04:00
parent d6f2498dbd
commit 616601a34a
5 changed files with 78 additions and 7 deletions

50
main.go
View File

@@ -2,20 +2,52 @@ package main
import (
"fmt"
"io"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/resendlabs/resend-go"
"github.com/spf13/cobra"
)
const RESEND_API_KEY = "RESEND_API_KEY"
const RESEND_FROM = "RESEND_FROM"
var (
from string
to []string
subject string
body string
attachments []string
)
var rootCmd = &cobra.Command{
Use: "email",
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 {
p := tea.NewProgram(NewModel())
if hasStdin() {
b, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
body = string(b)
}
if len(to) > 0 && from != "" && subject != "" && body != "" {
err := sendEmail(to, from, subject, body, attachments)
if err != nil {
return err
}
return nil
}
p := tea.NewProgram(NewModel(resend.SendEmailRequest{
From: from,
To: to,
Subject: subject,
Text: body,
}))
_, err := p.Run()
if err != nil {
return err
@@ -24,6 +56,22 @@ var rootCmd = &cobra.Command{
},
}
// hasStdin returns whether there is data in stdin.
func hasStdin() bool {
stat, err := os.Stdin.Stat()
return err == nil && (stat.Mode()&os.ModeCharDevice) == 0
}
func init() {
rootCmd.Flags().StringSliceVar(&to, "bcc", []string{}, "Blind carbon copy recipients")
rootCmd.Flags().StringSliceVar(&to, "cc", []string{}, "Carbon copy recipients")
rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments")
rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipient emails")
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's body (markdown)")
rootCmd.Flags().StringVarP(&from, "from", "f", os.Getenv(RESEND_FROM), "Email's sender ($RESEND_FROM)")
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")
}
func main() {
key := os.Getenv(RESEND_API_KEY)
if key == "" {