From e48b6ce45ce16784f10d2be720a31efb5ee23833 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 08:30:43 -0500 Subject: [PATCH 1/2] fix(tasks): send explicit empty title and notes in tasks update The Tasks API struct tags Title and Notes omitempty, so tasks update --notes '' and --title '' sent PATCH {} and changed nothing, although their help says "set empty to clear". Force the empty values into the PATCH, as calendar update does for summaries and descriptions. A task is always needsAction or completed, so --status '' is now a usage error and its help no longer offers to clear it. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + docs/commands/gog-tasks-update.md | 2 +- internal/cmd/tasks_items.go | 2 +- internal/cmd/tasks_update_clear_test.go | 67 +++++++++++++++++++++++++ internal/cmd/tasks_update_plan.go | 11 +++- 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 internal/cmd/tasks_update_clear_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..e7f803988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Tasks: make `tasks update --notes ''` and `--title ''` clear the field as their help says, instead of sending an empty PATCH that changed nothing, and reject `--status ''` with a usage error because a task is always `needsAction` or `completed`. — thanks @saariuslystoned. + ## 0.48.0 - 2026-11-05 **Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates. diff --git a/docs/commands/gog-tasks-update.md b/docs/commands/gog-tasks-update.md index c4f543c0a..1bf05b464 100644 --- a/docs/commands/gog-tasks-update.md +++ b/docs/commands/gog-tasks-update.md @@ -39,7 +39,7 @@ gog tasks (task) update (edit,set) [flags] | `--readonly` | `bool` | false | Block mutating API requests at runtime; auth add also requests read-only OAuth scopes | | `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) | | `--select`
`--pick`
`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. | -| `--status` | `string` | | New status: needsAction\|completed (set empty to clear) | +| `--status` | `string` | | New status: needsAction\|completed | | `--title` | `string` | | New title (set empty to clear) | | `-v`
`--verbose` | `bool` | | Enable verbose logging | | `--version` | `kong.VersionFlag` | | Print version and exit | diff --git a/internal/cmd/tasks_items.go b/internal/cmd/tasks_items.go index 10f094fc8..2aab09ff2 100644 --- a/internal/cmd/tasks_items.go +++ b/internal/cmd/tasks_items.go @@ -349,7 +349,7 @@ type TasksUpdateCmd struct { Title string `name:"title" help:"New title (set empty to clear)"` Notes string `name:"notes" help:"New notes (set empty to clear)"` Due string `name:"due" help:"New due date (RFC3339 or YYYY-MM-DD; time may be ignored; set empty to clear)"` - Status string `name:"status" help:"New status: needsAction|completed (set empty to clear)"` + Status string `name:"status" help:"New status: needsAction|completed"` } func (c *TasksUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags *RootFlags) error { diff --git a/internal/cmd/tasks_update_clear_test.go b/internal/cmd/tasks_update_clear_test.go new file mode 100644 index 000000000..d299d9f4c --- /dev/null +++ b/internal/cmd/tasks_update_clear_test.go @@ -0,0 +1,67 @@ +package cmd + +import ( + "errors" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" +) + +// runTasksUpdatePatch runs tasks update against a fake Tasks server and +// returns the PATCH body it sent ("" when no PATCH was sent). +func runTasksUpdatePatch(t *testing.T, args ...string) (string, error) { + t.Helper() + var patched string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch { + case r.Method == http.MethodGet && r.URL.Path == "/tasks/v1/users/@me/lists": + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"items":[{"id":"l1","title":"One"}]}`)) + case r.Method == http.MethodPatch && r.URL.Path == "/tasks/v1/lists/l1/tasks/t1": + body, _ := io.ReadAll(r.Body) + patched = strings.TrimSpace(string(body)) + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"id":"t1","title":"Task","status":"needsAction"}`)) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(srv.Close) + + ctx := withTasksTestService(newCmdRuntimeJSONOutputContext(t, io.Discard, io.Discard), newTasksServiceFromServer(t, srv)) + err := runKong(t, &TasksUpdateCmd{}, append([]string{"l1", "t1"}, args...), ctx, &RootFlags{Account: "a@b.com"}) + return patched, err +} + +func TestTasksUpdateCmd_EmptyNotesAndTitleAreSent(t *testing.T) { + for _, tc := range []struct { + args []string + want string + }{ + {args: []string{"--notes", ""}, want: `{"notes":""}`}, + {args: []string{"--title", ""}, want: `{"title":""}`}, + {args: []string{"--due", ""}, want: `{"due":null}`}, + {args: []string{"--notes", "keep"}, want: `{"notes":"keep"}`}, + } { + got, err := runTasksUpdatePatch(t, tc.args...) + if err != nil { + t.Fatalf("%v: %v", tc.args, err) + } + if got != tc.want { + t.Fatalf("%v sent PATCH %s, want %s", tc.args, got, tc.want) + } + } +} + +func TestTasksUpdateCmd_EmptyStatusIsUsageError(t *testing.T) { + got, err := runTasksUpdatePatch(t, "--status", "") + var exitErr *ExitError + if !errors.As(err, &exitErr) || exitErr.Code != 2 { + t.Fatalf("err = %v, want usage error", err) + } + if got != "" { + t.Fatalf("sent PATCH %s before rejecting", got) + } +} diff --git a/internal/cmd/tasks_update_plan.go b/internal/cmd/tasks_update_plan.go index 4c2e4b271..4dddcc718 100644 --- a/internal/cmd/tasks_update_plan.go +++ b/internal/cmd/tasks_update_plan.go @@ -53,12 +53,20 @@ func newTasksUpdatePlan(input tasksUpdateInput, fields tasksUpdateFields) (tasks } changed := false + // Title and Notes are omitempty in the API struct; force an explicit empty + // value into the PATCH so "set empty to clear" clears instead of sending {}. if fields.Title { plan.Patch.Title = strings.TrimSpace(input.Title) + if plan.Patch.Title == "" { + plan.Patch.ForceSendFields = append(plan.Patch.ForceSendFields, "Title") + } changed = true } if fields.Notes { plan.Patch.Notes = strings.TrimSpace(input.Notes) + if plan.Patch.Notes == "" { + plan.Patch.ForceSendFields = append(plan.Patch.ForceSendFields, "Notes") + } changed = true } if fields.Due { @@ -81,7 +89,8 @@ func newTasksUpdatePlan(input tasksUpdateInput, fields tasksUpdateFields) (tasks if !changed { return tasksUpdatePlan{}, usage("no fields to update (set at least one of: --title, --notes, --due, --status)") } - if fields.Status && plan.Patch.Status != "" && plan.Patch.Status != taskStatusNeedsAction && plan.Patch.Status != taskStatusCompleted { + // A task is always needsAction or completed; there is no empty status to set. + if fields.Status && plan.Patch.Status != taskStatusNeedsAction && plan.Patch.Status != taskStatusCompleted { return tasksUpdatePlan{}, usage("invalid --status (expected needsAction or completed)") } return plan, nil From 5b0dd6ecffbb66bbffca90163e78ea0abc0107d6 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:01:09 -0500 Subject: [PATCH 2/2] docs(changelog): reference #1313 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f803988..3d9bceb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Tasks: make `tasks update --notes ''` and `--title ''` clear the field as their help says, instead of sending an empty PATCH that changed nothing, and reject `--status ''` with a usage error because a task is always `needsAction` or `completed`. — thanks @saariuslystoned. +- Tasks: make `tasks update --notes ''` and `--title ''` clear the field as their help says, instead of sending an empty PATCH that changed nothing, and reject `--status ''` with a usage error because a task is always `needsAction` or `completed`. (#1313) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05