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: 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.
Expand Down
17 changes: 12 additions & 5 deletions internal/cmd/sheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down
6 changes: 1 addition & 5 deletions internal/cmd/sheets_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
28 changes: 28 additions & 0 deletions internal/cmd/sheets_plain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading