(cmd *cobra.Command, args []string)
| 54 | } |
| 55 | |
| 56 | func (c *habitCompleteCommand) run(cmd *cobra.Command, args []string) error { |
| 57 | if err := requireAuth(); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | id, err := strconv.ParseInt(args[0], 10, 64) |
| 62 | if err != nil { |
| 63 | return output.ErrUsage(fmt.Sprintf("invalid habit ID: %s", args[0])) |
| 64 | } |
| 65 | |
| 66 | date := c.date |
| 67 | if date == "" { |
| 68 | date = time.Now().Format("2006-01-02") |
| 69 | } |
| 70 | |
| 71 | ctx := cmd.Context() |
| 72 | result, err := sdk.Habits().Complete(ctx, date, id) |
| 73 | if err != nil { |
| 74 | return convertSDKError(err) |
| 75 | } |
| 76 | |
| 77 | if writer.IsStyled() { |
| 78 | fmt.Fprintf(cmd.OutOrStdout(), "Habit %s completed for %s.%s\n", args[0], date, extractMutationInfoFromResult(result)) |
| 79 | return nil |
| 80 | } |
| 81 | |
| 82 | normalized, nerr := normalizeAny(result) |
| 83 | if nerr != nil { |
| 84 | return writeOK(nil, output.WithSummary(fmt.Sprintf("Habit %s completed for %s", args[0], date))) |
| 85 | } |
| 86 | return writeOK(normalized, output.WithSummary(fmt.Sprintf("Habit %s completed for %s", args[0], date))) |
| 87 | } |
| 88 | |
| 89 | // uncomplete |
| 90 |
nothing calls this directly
no test coverage detected