diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..7dacb9ddf 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. (#1316) — 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..8e9a8dd87 100644 --- a/internal/cmd/sheets_plain_test.go +++ b/internal/cmd/sheets_plain_test.go @@ -80,3 +80,31 @@ 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: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:D3"}, svc) + if result.err != nil { + t.Fatalf("execute: %v", result.err) + } + 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) + } +}