From 7fbb0a14b96bcb4f160f5bf92294ba32dad2ea4c Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Sat, 30 May 2026 00:41:28 -0400 Subject: [PATCH] feat(sheets): add --inherit-from-before to sheets insert (#655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `gog sheets insert` always derived InsertDimensionRequest.inheritFromBefore from --after, so there was no way to insert columns/rows with plain formatting next to a formatted neighbour (the reported case: plain 0–100 score columns inserted beside a currency column first rendered as currency). Add a tri-state `--inherit-from-before` flag (*bool): omitted keeps the prior default (inherit only with --after), `--inherit-from-before=false` forces plain formatting, and `--inherit-from-before` forces inheritance on a before-insert. Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 1 + internal/cmd/sheets_insert.go | 8 +++++++ internal/cmd/sheets_insert_test.go | 34 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bab9b35cd..db63a20ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Docs: add `--heading-level N` (1..6 shortcut) and `--named-style NAME` (full enum) to `gog docs format` so existing paragraphs can be promoted to `HEADING_1`..`HEADING_6`, `TITLE`, `SUBTITLE`, or `NORMAL_TEXT`. Both set `paragraphStyle.namedStyleType` on the existing UpdateParagraphStyle request and compose cleanly with `--alignment` / `--line-spacing`. (#605) - Sheets: add `gog sheets reorder-tab --tab= --to=N` to move a tab to a specific 0-based position via `updateSheetProperties` with field mask `index`. `--tab` accepts a title or a numeric sheet ID; `--to=0` is force-sent so the leftmost target reaches the wire as `"index":0`. Aliases: `move-tab`, `reorder-sheet`, `move-sheet`. (#603) - Docs: add `gog docs insert-table --rows N --cols M [--index N | --at-end] [--values-json [[...]]] [--tab=STRING]` to insert a native Google Docs table directly via `InsertTableRequest`, bypassing the markdown writer. `--values-json` takes a JSON 2D string array whose dimensions must match `--rows`x`--cols`. Empty `--values-json` produces an empty table structure. (#602) +- Sheets: add `--inherit-from-before` to `gog sheets insert` to control whether inserted rows/columns adopt the adjacent line's number format and styling, independent of `--after`. The flag is tri-state: omitted keeps the prior behaviour (inherit only with `--after`), `--inherit-from-before=false` forces plain formatting (e.g. plain-score columns next to a currency column), and `--inherit-from-before` forces inheritance on a before-insert. Maps to `InsertDimensionRequest.inheritFromBefore`. (#655) ### Fixed diff --git a/internal/cmd/sheets_insert.go b/internal/cmd/sheets_insert.go index 335900365..aa6351257 100644 --- a/internal/cmd/sheets_insert.go +++ b/internal/cmd/sheets_insert.go @@ -18,6 +18,9 @@ type SheetsInsertCmd struct { Start int64 `arg:"" name:"start" help:"Position before which to insert (1-based; for cols 1=A, 2=B)"` Count int64 `name:"count" help:"Number of rows/columns to insert" default:"1"` After bool `name:"after" help:"Insert after the position instead of before"` + // *bool so an unset flag keeps the historical default (inherit only when + // --after); passing --inherit-from-before[=false] overrides it explicitly. + InheritFromBefore *bool `name:"inherit-from-before" help:"Inherit number format / styling from the adjacent row/column. Defaults to true with --after, false otherwise; set to false to insert with plain formatting."` } func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error { @@ -58,7 +61,12 @@ func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error { startIndex = c.Start } endIndex := startIndex + c.Count + // Default: inherit formatting only when inserting after an existing line. + // An explicit --inherit-from-before[=false] overrides that default. inheritFromBefore := c.After + if c.InheritFromBefore != nil { + inheritFromBefore = *c.InheritFromBefore + } if dryRunErr := dryRunExit(ctx, flags, "sheets.insert", map[string]any{ "spreadsheet_id": spreadsheetID, diff --git a/internal/cmd/sheets_insert_test.go b/internal/cmd/sheets_insert_test.go index a6db69715..53058d030 100644 --- a/internal/cmd/sheets_insert_test.go +++ b/internal/cmd/sheets_insert_test.go @@ -124,6 +124,40 @@ func TestSheetsInsertCmd(t *testing.T) { } }) + t.Run("insert after without inheriting formatting", func(t *testing.T) { + gotInsert = nil + cmd := &SheetsInsertCmd{} + if err := runKong(t, cmd, []string{ + "s1", "Data", "rows", "2", "--count", "1", "--after", "--inherit-from-before=false", + }, ctx, flags); err != nil { + t.Fatalf("insert rows: %v", err) + } + if gotInsert == nil { + t.Fatal("expected insertDimension request") + } + // --after would default inheritFromBefore=true; the explicit flag overrides it. + if gotInsert.InheritFromBefore { + t.Fatal("expected inheritFromBefore=false when --inherit-from-before=false overrides --after") + } + }) + + t.Run("insert before with explicit inherit", func(t *testing.T) { + gotInsert = nil + cmd := &SheetsInsertCmd{} + if err := runKong(t, cmd, []string{ + "s1", "Data", "rows", "2", "--count", "1", "--inherit-from-before", + }, ctx, flags); err != nil { + t.Fatalf("insert rows: %v", err) + } + if gotInsert == nil { + t.Fatal("expected insertDimension request") + } + // before-insert defaults inheritFromBefore=false; the explicit flag overrides it. + if !gotInsert.InheritFromBefore { + t.Fatal("expected inheritFromBefore=true when --inherit-from-before is set") + } + }) + t.Run("insert cols before", func(t *testing.T) { gotInsert = nil cmd := &SheetsInsertCmd{}