(cmd *cobra.Command, args []string)
| 144 | } |
| 145 | |
| 146 | func (c *todoAddCommand) run(cmd *cobra.Command, args []string) error { |
| 147 | if err := requireAuth(); err != nil { |
| 148 | return err |
| 149 | } |
| 150 | |
| 151 | title := c.title |
| 152 | if title != "" && len(args) > 0 { |
| 153 | return output.ErrUsage("--title and positional argument are mutually exclusive") |
| 154 | } |
| 155 | if title == "" && len(args) > 0 { |
| 156 | title = args[0] |
| 157 | } |
| 158 | if title == "" && !stdinIsTerminal() { |
| 159 | var err error |
| 160 | title, err = readStdin() |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | } |
| 165 | if title == "" { |
| 166 | return output.ErrUsageHint("title is required", |
| 167 | "hey todo add \"Buy milk\" or hey todo add --title \"Buy milk\"") |
| 168 | } |
| 169 | |
| 170 | ctx := cmd.Context() |
| 171 | result, err := sdk.CalendarTodos().Create(ctx, title, c.date) |
| 172 | if err != nil { |
| 173 | return convertSDKError(err) |
| 174 | } |
| 175 | |
| 176 | if writer.IsStyled() { |
| 177 | fmt.Fprintln(cmd.OutOrStdout(), "Todo created.") |
| 178 | return nil |
| 179 | } |
| 180 | |
| 181 | normalized, nerr := normalizeAny(result) |
| 182 | if nerr != nil { |
| 183 | return writeOK(nil, output.WithSummary("Todo created")) |
| 184 | } |
| 185 | return writeOK(normalized, output.WithSummary("Todo created")) |
| 186 | } |
| 187 | |
| 188 | // complete |
| 189 |
nothing calls this directly
no test coverage detected