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

- Sheets: return an empty `notes` or `links` array from `sheets notes --json` and `sheets links --json` when the range has none, instead of `null`. With `--results-only`, empty notes now print `[]` instead of `null`, and empty links print `[]` instead of the whole envelope. (#1314) — 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
2 changes: 1 addition & 1 deletion internal/cmd/sheets_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *SheetsLinksGetCmd) Run(ctx context.Context, flags *RootFlags) error {
return err
}

var links []sheetsCellLink
links := []sheetsCellLink{}

for _, sheet := range resp.Sheets {
if sheet == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/sheets_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *SheetsNotesCmd) Run(ctx context.Context, flags *RootFlags) error {
return err
}

var notes []sheetsCellNote
notes := []sheetsCellNote{}

for _, sheet := range resp.Sheets {
if sheet == nil {
Expand Down
55 changes: 55 additions & 0 deletions internal/cmd/sheets_notes_links_empty_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
)

// A range with no notes or links must still be a JSON array, so scripts can
// use `jq '.[]'` or `length` on it, with and without --results-only.
func TestSheetsNotesAndLinks_EmptyRangeJSONIsEmptyArray(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"sheets": []map[string]any{{
"properties": map[string]any{"title": "Sheet1"},
"data": []map[string]any{{
"rowData": []map[string]any{{"values": []map[string]any{{"formattedValue": "plain"}}}},
}},
}},
})
}))
defer srv.Close()
svc := newSheetsServiceFromServer(t, srv)

for _, tc := range []struct {
command string
key string
}{
{command: "notes", key: "notes"},
{command: "links", key: "links"},
} {
envelope := executeWithSheetsTestService(t, []string{"--json", "--account", "a@b.com", "sheets", tc.command, "s1", "Sheet1!A1:A1"}, svc)
if envelope.err != nil {
t.Fatalf("%s: %v", tc.command, envelope.err)
}
var got map[string]json.RawMessage
if err := json.Unmarshal([]byte(envelope.stdout), &got); err != nil {
t.Fatalf("%s json: %v (%q)", tc.command, err, envelope.stdout)
}
if string(got[tc.key]) != "[]" {
t.Fatalf("%s: %q = %s, want []", tc.command, tc.key, got[tc.key])
}

unwrapped := executeWithSheetsTestService(t, []string{"--json", "--results-only", "--account", "a@b.com", "sheets", tc.command, "s1", "Sheet1!A1:A1"}, svc)
if unwrapped.err != nil {
t.Fatalf("%s --results-only: %v", tc.command, unwrapped.err)
}
if strings.TrimSpace(unwrapped.stdout) != "[]" {
t.Fatalf("%s --results-only = %s, want []", tc.command, strings.TrimSpace(unwrapped.stdout))
}
}
}
Loading