From 9b5e277846bc738799765aba1c23e4527bcf0fca Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:18:00 -0500 Subject: [PATCH 1/2] fix(drive): accept commas in drive labels file apply field flags The --text, --selection, --integer, --date and --user flags were plain string slices, so the CLI split each value on commas before parseDriveLabelFieldAssignment saw it. The documented field=a,b forms and any text containing a comma failed with "label field assignments must be field=value". Mark the flags sep:"none" and keep a text value whole, since a text field holds one value. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + internal/cmd/drive_labels.go | 22 ++++----- internal/cmd/drive_labels_comma_test.go | 60 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 internal/cmd/drive_labels_comma_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..23abe7ba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Drive: accept commas in `drive labels file apply` field flags. The CLI split each `--text`, `--selection`, `--integer`, `--date` and `--user` value on commas before gog parsed it, so the documented `field=a,b` forms and any text value containing a comma failed with "label field assignments must be field=value". Text values now keep their commas, and the other fields take comma-separated values as documented. — 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/internal/cmd/drive_labels.go b/internal/cmd/drive_labels.go index cda5666f9..de5a43553 100644 --- a/internal/cmd/drive_labels.go +++ b/internal/cmd/drive_labels.go @@ -96,11 +96,11 @@ func (c *DriveLabelsFileListCmd) Run(ctx context.Context, flags *RootFlags) erro type DriveLabelsFileApplyCmd struct { FileID string `arg:"" name:"fileId" help:"Drive file ID"` LabelID string `arg:"" name:"labelId" help:"Label ID or labels/{id}"` - Text []string `name:"text" help:"Set text field as field=value (repeatable)"` - Selection []string `name:"selection" help:"Set selection field as field=choiceId[,choiceId] (repeatable)"` - Integer []string `name:"integer" help:"Set integer field as field=123[,456] (repeatable)"` - Date []string `name:"date" help:"Set date field as field=YYYY-MM-DD[,YYYY-MM-DD] (repeatable)"` - User []string `name:"user" help:"Set user field as field=email[,email] (repeatable)"` + Text []string `name:"text" sep:"none" help:"Set text field as field=value (repeatable)"` + Selection []string `name:"selection" sep:"none" help:"Set selection field as field=choiceId[,choiceId] (repeatable)"` + Integer []string `name:"integer" sep:"none" help:"Set integer field as field=123[,456] (repeatable)"` + Date []string `name:"date" sep:"none" help:"Set date field as field=YYYY-MM-DD[,YYYY-MM-DD] (repeatable)"` + User []string `name:"user" sep:"none" help:"Set user field as field=email[,email] (repeatable)"` Unset []string `name:"unset" help:"Unset field ID (repeatable)"` FieldsJSON string `name:"fields-json" help:"Simple JSON object of fieldId to string/number/bool/string-array values (strings become text fields)"` } @@ -339,11 +339,13 @@ func driveLabelFieldMods(c *DriveLabelsFileApplyCmd) ([]*drive.LabelFieldModific } return nil } - if err := add(c.Text, func(m *drive.LabelFieldModification, values []string) error { - m.SetTextValues = values - return nil - }); err != nil { - return nil, err + // A text field holds one value, so a comma in it is part of the text. + for _, item := range c.Text { + field, value, ok := strings.Cut(strings.TrimSpace(item), "=") + if !ok || strings.TrimSpace(field) == "" { + return nil, usage("label field assignments must be field=value") + } + mods = append(mods, &drive.LabelFieldModification{FieldId: strings.TrimSpace(field), SetTextValues: []string{strings.TrimSpace(value)}}) } if err := add(c.Selection, func(m *drive.LabelFieldModification, values []string) error { m.SetSelectionValues = values diff --git a/internal/cmd/drive_labels_comma_test.go b/internal/cmd/drive_labels_comma_test.go new file mode 100644 index 000000000..a47b2c5af --- /dev/null +++ b/internal/cmd/drive_labels_comma_test.go @@ -0,0 +1,60 @@ +package cmd + +import ( + "encoding/json" + "io" + "net/http" + "reflect" + "testing" + + "google.golang.org/api/drive/v3" +) + +// The field flags are parsed by the CLI, not built in Go: a comma in the +// flag value must reach gog's own parser, so text keeps its comma and the +// documented field=a,b forms produce multiple values. +func TestDriveLabelsFileApply_CommaValuesThroughCLI(t *testing.T) { + var got []*drive.LabelFieldModification + svc, closeSvc := newDriveTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost || r.URL.Path != "/files/file1/modifyLabels" { + http.NotFound(w, r) + return + } + var req drive.ModifyLabelsRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil && err != io.EOF { + t.Fatalf("decode body: %v", err) + } + got = req.LabelModifications[0].FieldModifications + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{"modifiedLabels": []map[string]any{{"id": "label1"}}}) + })) + defer closeSvc() + + ctx := withDriveTestService(newCmdRuntimeJSONOutputContext(t, io.Discard, io.Discard), svc) + err := runKong(t, &DriveLabelsFileApplyCmd{}, []string{ + "file1", "label1", + "--text", "note=Hello, world", + "--selection", "status=c1,c2", + "--integer", "count=1,2", + "--user", "owners=a@example.com,b@example.com", + }, ctx, &RootFlags{Account: "a@example.com", Force: true}) + if err != nil { + t.Fatalf("apply: %v", err) + } + byField := map[string]*drive.LabelFieldModification{} + for _, mod := range got { + byField[mod.FieldId] = mod + } + if v := byField["note"]; v == nil || !reflect.DeepEqual(v.SetTextValues, []string{"Hello, world"}) { + t.Fatalf("note = %#v, want one text value with its comma", v) + } + if v := byField["status"]; v == nil || !reflect.DeepEqual(v.SetSelectionValues, []string{"c1", "c2"}) { + t.Fatalf("status = %#v, want two selection values", v) + } + if v := byField["count"]; v == nil || !reflect.DeepEqual([]int64(v.SetIntegerValues), []int64{1, 2}) { + t.Fatalf("count = %#v, want two integer values", v) + } + if v := byField["owners"]; v == nil || !reflect.DeepEqual(v.SetUserValues, []string{"a@example.com", "b@example.com"}) { + t.Fatalf("owners = %#v, want two user values", v) + } +} From cc2a5929a125a760fc4c6ddb141ce2100f487cea Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:01:30 -0500 Subject: [PATCH 2/2] docs(changelog): reference #1319 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 23abe7ba3..7804e082b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Drive: accept commas in `drive labels file apply` field flags. The CLI split each `--text`, `--selection`, `--integer`, `--date` and `--user` value on commas before gog parsed it, so the documented `field=a,b` forms and any text value containing a comma failed with "label field assignments must be field=value". Text values now keep their commas, and the other fields take comma-separated values as documented. — thanks @saariuslystoned. +- Drive: accept commas in `drive labels file apply` field flags. The CLI split each `--text`, `--selection`, `--integer`, `--date` and `--user` value on commas before gog parsed it, so the documented `field=a,b` forms and any text value containing a comma failed with "label field assignments must be field=value". Text values now keep their commas, and the other fields take comma-separated values as documented. (#1319) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05