From caf0a1823a0818c32489f1589afdf75dda8c446d Mon Sep 17 00:00:00 2001 From: Jeroen Bulters Date: Wed, 11 Feb 2026 23:22:25 +0100 Subject: [PATCH] Add initial no-tty implementation --- main.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a820b78..9a2460e 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,7 @@ var ( smtpEncryption string smtpInsecureSkipVerify bool resendAPIKey string + noTTY bool ) var rootCmd = &cobra.Command{ @@ -115,6 +116,30 @@ var rootCmd = &cobra.Command{ body += "\n\n" + signature } + if noTTY && (len(to) == 0 || from == "" || subject == "" || body == "" || preview) { + var missing []string + if from == "" { + missing = append(missing, "--from") + } + if len(to) == 0 { + missing = append(missing, "--to") + } + if subject == "" { + missing = append(missing, "--subject") + } + if body == "" { + missing = append(missing, "--body") + } + if preview { + missing = append(missing, "(--preview is not supported with --no-tty)") + } + err := fmt.Errorf("missing required flags in --no-tty mode: %s", strings.Join(missing, ", ")) + fmt.Fprintln(os.Stderr, err.Error()) + cmd.SilenceUsage = true + cmd.SilenceErrors = true + return err + } + if len(to) > 0 && from != "" && subject != "" && body != "" && !preview { var err error switch deliveryMethod { @@ -128,8 +153,12 @@ var rootCmd = &cobra.Command{ if err != nil { cmd.SilenceUsage = true cmd.SilenceErrors = true + if noTTY { + fmt.Fprintln(os.Stderr, err.Error()) + } else { fmt.Println(errorStyle.Render(err.Error())) - return err + } + return err } fmt.Print(emailSummary(to, subject)) return nil @@ -226,6 +255,7 @@ func init() { rootCmd.Flags().BoolVarP(&smtpInsecureSkipVerify, "smtp.insecure", "i", envInsecureSkipVerify, "Skip TLS verification with SMTP server"+commentStyle.Render("($"+PopSMTPInsecureSkipVerify+")")) envResendAPIKey := os.Getenv(ResendAPIKey) rootCmd.Flags().StringVarP(&resendAPIKey, "resend.key", "r", envResendAPIKey, "API key for the Resend.com"+commentStyle.Render("($"+ResendAPIKey+")")) + rootCmd.Flags().BoolVarP(&noTTY, "no-tty", "n", false, "Don't use the interactive TUI, errors are written to STDERR") rootCmd.CompletionOptions.HiddenDefaultCmd = true