MCPcopy Create free account
hub / github.com/basecamp/hey-cli / run

Method run

internal/cmd/todo.go:146–186  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

144}
145
146func (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

Callers

nothing calls this directly

Calls 8

WithSummaryFunction · 0.92
requireAuthFunction · 0.85
stdinIsTerminalFunction · 0.85
readStdinFunction · 0.85
convertSDKErrorFunction · 0.85
normalizeAnyFunction · 0.85
writeOKFunction · 0.85
IsStyledMethod · 0.80

Tested by

no test coverage detected