From 420db383d1dde5c195b164a649574f3024112b11 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 07:54:42 -0500 Subject: [PATCH 1/3] fix(sheets): keep each sheet row on one line in text output sheets get and sheets datasource table read joined raw cell values with tabs, so a cell with a line break or tab split its row in text and --plain output. Escape cells with the existing oneLine helper, as the links, notes, format and validation tables already do. JSON output is unchanged. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ internal/cmd/sheets.go | 17 ++++++++++----- internal/cmd/sheets_datasource.go | 6 +----- internal/cmd/sheets_plain_test.go | 35 +++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..51aac81c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Sheets: keep each sheet row on one line in `sheets get` and `sheets datasource table read` text and `--plain` output. Line breaks inside a cell are written as `\n` and tabs as spaces, as the links, notes and format tables already do, so a multi-line cell no longer splits its row. JSON output is unchanged. — 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/sheets.go b/internal/cmd/sheets.go index 3f5915541..10497f0df 100644 --- a/internal/cmd/sheets.go +++ b/internal/cmd/sheets.go @@ -166,15 +166,22 @@ func (c *SheetsGetCmd) Run(ctx context.Context, flags *RootFlags) error { w, flush := tableWriter(ctx) defer flush() for _, row := range resp.Values { - cells := make([]string, len(row)) - for i, cell := range row { - cells[i] = fmt.Sprintf("%v", cell) - } - fmt.Fprintln(w, strings.Join(cells, "\t")) + fmt.Fprintln(w, sheetsValueRowLine(row)) } return nil } +// sheetsValueRowLine joins one row of cell values with tabs. Line breaks and +// tabs inside a cell are escaped with oneLine so each sheet row stays one +// output row, as in the other Sheets cell tables. +func sheetsValueRowLine(row []interface{}) string { + cells := make([]string, len(row)) + for i, cell := range row { + cells[i] = oneLine(fmt.Sprintf("%v", cell)) + } + return strings.Join(cells, "\t") +} + type SheetsUpdateCmd struct { SpreadsheetID string `arg:"" name:"spreadsheetId" help:"Spreadsheet ID"` Range string `arg:"" name:"range" help:"Range (A1 notation or named range name; e.g. Sheet1!A1:B2 or MyNamedRange)"` diff --git a/internal/cmd/sheets_datasource.go b/internal/cmd/sheets_datasource.go index 804288d89..943bb3291 100644 --- a/internal/cmd/sheets_datasource.go +++ b/internal/cmd/sheets_datasource.go @@ -347,11 +347,7 @@ func (c *SheetsDataSourceTableReadCmd) Run(ctx context.Context, flags *RootFlags w, flush := tableWriter(ctx) defer flush() for _, row := range rowsOut { - cells := make([]string, len(row)) - for i, cell := range row { - cells[i] = fmt.Sprintf("%v", cell) - } - fmt.Fprintln(w, strings.Join(cells, "\t")) + fmt.Fprintln(w, sheetsValueRowLine(row)) } return nil } diff --git a/internal/cmd/sheets_plain_test.go b/internal/cmd/sheets_plain_test.go index 9ae870884..c34ec4856 100644 --- a/internal/cmd/sheets_plain_test.go +++ b/internal/cmd/sheets_plain_test.go @@ -80,3 +80,38 @@ func TestSheetsMetadataCmd_PlainOutputTSV(t *testing.T) { t.Errorf("metadata table header missing tab delimiters in plain mode: %q", got) } } + +// TestSheetsGetCmd_PlainKeepsMultilineCellsOnOneRow verifies that a cell with +// line breaks or tabs stays in its own row and column, as the other Sheets +// cell tables (links, notes, format) already do through oneLine. +func TestSheetsGetCmd_PlainKeepsMultilineCellsOnOneRow(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{ + "range": "Sheet1!A1:C2", + "values": [][]string{ + {"Name", "Address", "Note"}, + {"Alice", "1 Main St\nBerlin", "a\tb"}, + }, + }) + })) + defer srv.Close() + + svc := newSheetsServiceFromServer(t, srv) + result := executeWithSheetsTestService(t, []string{"--plain", "--account", "a@b.com", "sheets", "get", "spreadsheet1", "Sheet1!A1:C2"}, svc) + if result.err != nil { + t.Fatalf("execute: %v", result.err) + } + want := "Name\tAddress\tNote\nAlice\t1 Main St\\nBerlin\ta b\n" + if result.stdout != want { + t.Fatalf("stdout = %q, want %q", result.stdout, want) + } +} + +func TestSheetsValueRowLine(t *testing.T) { + t.Parallel() + got := sheetsValueRowLine([]interface{}{"a\r\nb", 3.5, true, "c\td", ""}) + if want := "a\\nb\t3.5\ttrue\tc d\t"; got != want { + t.Fatalf("sheetsValueRowLine = %q, want %q", got, want) + } +} From a020240c4e42b66c288fd19b7932760609cf5d00 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:01:22 -0500 Subject: [PATCH 2/3] docs(changelog): reference #1316 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 51aac81c1..7dacb9ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Sheets: keep each sheet row on one line in `sheets get` and `sheets datasource table read` text and `--plain` output. Line breaks inside a cell are written as `\n` and tabs as spaces, as the links, notes and format tables already do, so a multi-line cell no longer splits its row. JSON output is unchanged. — thanks @saariuslystoned. +- Sheets: keep each sheet row on one line in `sheets get` and `sheets datasource table read` text and `--plain` output. Line breaks inside a cell are written as `\n` and tabs as spaces, as the links, notes and format tables already do, so a multi-line cell no longer splits its row. JSON output is unchanged. (#1316) — thanks @saariuslystoned. ## 0.48.0 - 2026-11-05 From 6a3b0c505fef573c23baf857d75ed5a952815496 Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:42:16 -0500 Subject: [PATCH 3/3] test(sheets): cover CRLF and scalar cells through sheets get Move the helper-only cases into the command-path test. Co-Authored-By: Claude Opus 5.5 --- internal/cmd/sheets_plain_test.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/internal/cmd/sheets_plain_test.go b/internal/cmd/sheets_plain_test.go index c34ec4856..8e9a8dd87 100644 --- a/internal/cmd/sheets_plain_test.go +++ b/internal/cmd/sheets_plain_test.go @@ -88,30 +88,23 @@ func TestSheetsGetCmd_PlainKeepsMultilineCellsOnOneRow(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{ - "range": "Sheet1!A1:C2", - "values": [][]string{ + "range": "Sheet1!A1:D3", + "values": [][]any{ {"Name", "Address", "Note"}, {"Alice", "1 Main St\nBerlin", "a\tb"}, + {"Bob", "2 High St\r\nParis", 3.5, true}, }, }) })) defer srv.Close() svc := newSheetsServiceFromServer(t, srv) - result := executeWithSheetsTestService(t, []string{"--plain", "--account", "a@b.com", "sheets", "get", "spreadsheet1", "Sheet1!A1:C2"}, svc) + result := executeWithSheetsTestService(t, []string{"--plain", "--account", "a@b.com", "sheets", "get", "spreadsheet1", "Sheet1!A1:D3"}, svc) if result.err != nil { t.Fatalf("execute: %v", result.err) } - want := "Name\tAddress\tNote\nAlice\t1 Main St\\nBerlin\ta b\n" + want := "Name\tAddress\tNote\nAlice\t1 Main St\\nBerlin\ta b\nBob\t2 High St\\nParis\t3.5\ttrue\n" if result.stdout != want { t.Fatalf("stdout = %q, want %q", result.stdout, want) } } - -func TestSheetsValueRowLine(t *testing.T) { - t.Parallel() - got := sheetsValueRowLine([]interface{}{"a\r\nb", 3.5, true, "c\td", ""}) - if want := "a\\nb\t3.5\ttrue\tc d\t"; got != want { - t.Fatalf("sheetsValueRowLine = %q, want %q", got, want) - } -}