(ctx context.Context, flags *RootFlags, keep *KeepCmd)
| 313 | } |
| 314 | |
| 315 | func (c *KeepCreateCmd) Run(ctx context.Context, flags *RootFlags, keep *KeepCmd) error { |
| 316 | u := ui.FromContext(ctx) |
| 317 | |
| 318 | title := strings.TrimSpace(c.Title) |
| 319 | text := strings.TrimSpace(c.Text) |
| 320 | |
| 321 | if text == "" && len(c.Item) == 0 { |
| 322 | return usage("provide --text or at least one --item") |
| 323 | } |
| 324 | if text != "" && len(c.Item) > 0 { |
| 325 | return usage("--text and --item are mutually exclusive") |
| 326 | } |
| 327 | |
| 328 | items := make([]string, 0, len(c.Item)) |
| 329 | for _, raw := range c.Item { |
| 330 | item := strings.TrimSpace(raw) |
| 331 | if item == "" { |
| 332 | return usage("--item cannot be empty") |
| 333 | } |
| 334 | items = append(items, item) |
| 335 | } |
| 336 | |
| 337 | if dryRunErr := dryRunExit(ctx, flags, "keep.create", map[string]any{ |
| 338 | "title": title, |
| 339 | "text": text, |
| 340 | "items": items, |
| 341 | }); dryRunErr != nil { |
| 342 | return dryRunErr |
| 343 | } |
| 344 | |
| 345 | svc, err := getKeepService(ctx, flags, keep) |
| 346 | if err != nil { |
| 347 | return err |
| 348 | } |
| 349 | |
| 350 | note := &keepapi.Note{Title: title} |
| 351 | |
| 352 | if text != "" { |
| 353 | note.Body = &keepapi.Section{ |
| 354 | Text: &keepapi.TextContent{Text: text}, |
| 355 | } |
| 356 | } else { |
| 357 | listItems := make([]*keepapi.ListItem, 0, len(items)) |
| 358 | for _, item := range items { |
| 359 | listItems = append(listItems, &keepapi.ListItem{ |
| 360 | Text: &keepapi.TextContent{Text: item}, |
| 361 | }) |
| 362 | } |
| 363 | note.Body = &keepapi.Section{ |
| 364 | List: &keepapi.ListContent{ListItems: listItems}, |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | created, err := svc.Notes.Create(note).Context(ctx).Do() |
| 369 | if err != nil { |
| 370 | return err |
| 371 | } |
| 372 |
nothing calls this directly
no test coverage detected