Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. (#1319) — 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.
Expand Down
22 changes: 12 additions & 10 deletions internal/cmd/drive_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
}
Expand Down Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions internal/cmd/drive_labels_comma_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading