(cmd *cobra.Command, args []string)
| 47 | } |
| 48 | |
| 49 | func (c *composeCommand) run(cmd *cobra.Command, args []string) error { |
| 50 | if err := requireAuth(); err != nil { |
| 51 | return err |
| 52 | } |
| 53 | |
| 54 | if c.subject == "" { |
| 55 | return output.ErrUsageHint("--subject is required", "hey compose --to <email> --subject <subject> -m <message>") |
| 56 | } |
| 57 | |
| 58 | message := c.message |
| 59 | if message == "" { |
| 60 | if !stdinIsTerminal() { |
| 61 | var err error |
| 62 | message, err = readStdin() |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | if message == "" { |
| 67 | return output.ErrUsage("no message provided (use -m or --message to provide inline, or pipe to stdin)") |
| 68 | } |
| 69 | } else { |
| 70 | var err error |
| 71 | message, err = editor.Open("") |
| 72 | if err != nil { |
| 73 | return output.ErrAPI(0, fmt.Sprintf("could not open editor: %v", err)) |
| 74 | } |
| 75 | if message == "" { |
| 76 | return output.ErrUsage("empty message, aborting") |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | ctx := cmd.Context() |
| 82 | |
| 83 | if c.threadID != "" { |
| 84 | topicID, err := strconv.ParseInt(c.threadID, 10, 64) |
| 85 | if err != nil { |
| 86 | return output.ErrUsage(fmt.Sprintf("invalid thread ID: %s", c.threadID)) |
| 87 | } |
| 88 | if err := sdk.Messages().CreateTopicMessage(ctx, topicID, message); err != nil { |
| 89 | return convertSDKError(err) |
| 90 | } |
| 91 | } else { |
| 92 | to := parseAddresses(c.to) |
| 93 | cc := parseAddresses(c.cc) |
| 94 | bcc := parseAddresses(c.bcc) |
| 95 | if err := sdk.Messages().Create(ctx, c.subject, message, to, cc, bcc); err != nil { |
| 96 | return convertSDKError(err) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if writer.IsStyled() { |
| 101 | fmt.Fprintln(cmd.OutOrStdout(), "Message sent.") |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | return writeOK(nil, output.WithSummary("Message sent")) |
| 106 | } |
nothing calls this directly
no test coverage detected