Skip to content

Commit 8a9a908

Browse files
chrischallclaudesteipete
authored
feat(sheets): add --inherit-from-before to sheets insert (#658)
* feat(sheets): add --inherit-from-before to sheets insert `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. Regenerate the command reference (make docs-commands) so the flag is documented. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(sheets): validate insert formatting inheritance --------- Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 28e29cd commit 8a9a908

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Gmail: keep label IDs case-sensitive during label resolution and duplicate-name checks while still matching label names case-insensitively.
88
- Gmail: clarify that `gmail drafts delete` permanently deletes drafts and cannot be recovered. (#656, #659) — thanks @chrischall.
9+
- Sheets: add `--inherit-from-before` to `sheets insert` so callers can choose whether inserted rows/columns inherit formatting from the preceding or following neighbor. (#655, #658) — thanks @chrischall.
910
- Docs: update the bundled `gog` agent skill to preserve broad user OAuth scopes during reauth and rely on command guards for scoped execution.
1011

1112
## 0.19.0 - 2026-05-22

docs/commands/gog-sheets-insert.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ gog sheets (sheet) insert <spreadsheetId> <sheet> <dimension> <start> [flags]
3131
| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) |
3232
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
3333
| `--home` | `string` | | Override gogcli config/data/state/cache root (equivalent to GOG_HOME) |
34+
| `--inherit-from-before` | `*bool` | | Inherit number format / styling from the row/column before the insertion. Defaults to true with --after, false otherwise; false inherits from the row/column after the insertion. |
3435
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
3536
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
3637
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |

internal/cmd/sheets_insert.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type SheetsInsertCmd struct {
1818
Start int64 `arg:"" name:"start" help:"Position before which to insert (1-based; for cols 1=A, 2=B)"`
1919
Count int64 `name:"count" help:"Number of rows/columns to insert" default:"1"`
2020
After bool `name:"after" help:"Insert after the position instead of before"`
21+
// *bool so an unset flag keeps the historical default (inherit only when
22+
// --after); passing --inherit-from-before[=false] overrides it explicitly.
23+
InheritFromBefore *bool `name:"inherit-from-before" help:"Inherit number format / styling from the row/column before the insertion. Defaults to true with --after, false otherwise; false inherits from the row/column after the insertion."`
2124
}
2225

2326
func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error {
@@ -58,7 +61,15 @@ func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error {
5861
startIndex = c.Start
5962
}
6063
endIndex := startIndex + c.Count
64+
// Default: inherit formatting only when inserting after an existing line.
65+
// An explicit --inherit-from-before[=false] overrides that default.
6166
inheritFromBefore := c.After
67+
if c.InheritFromBefore != nil {
68+
inheritFromBefore = *c.InheritFromBefore
69+
}
70+
if inheritFromBefore && startIndex == 0 {
71+
return usagef("cannot inherit from the previous %s when inserting at position 1", dimLabel)
72+
}
6273

6374
if dryRunErr := dryRunExit(ctx, flags, "sheets.insert", map[string]any{
6475
"spreadsheet_id": spreadsheetID,

internal/cmd/sheets_insert_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,58 @@ func TestSheetsInsertCmd(t *testing.T) {
124124
}
125125
})
126126

127+
t.Run("insert after inheriting from following dimension", func(t *testing.T) {
128+
gotInsert = nil
129+
cmd := &SheetsInsertCmd{}
130+
if err := runKong(t, cmd, []string{
131+
"s1", "Data", "rows", "2", "--count", "1", "--after", "--inherit-from-before=false",
132+
}, ctx, flags); err != nil {
133+
t.Fatalf("insert rows: %v", err)
134+
}
135+
if gotInsert == nil {
136+
t.Fatal("expected insertDimension request")
137+
}
138+
// --after would default inheritFromBefore=true; the explicit flag overrides it
139+
// so the API inherits from the following adjacent row/column instead.
140+
if gotInsert.InheritFromBefore {
141+
t.Fatal("expected inheritFromBefore=false when --inherit-from-before=false overrides --after")
142+
}
143+
})
144+
145+
t.Run("insert before with explicit inherit", func(t *testing.T) {
146+
gotInsert = nil
147+
cmd := &SheetsInsertCmd{}
148+
if err := runKong(t, cmd, []string{
149+
"s1", "Data", "rows", "2", "--count", "1", "--inherit-from-before",
150+
}, ctx, flags); err != nil {
151+
t.Fatalf("insert rows: %v", err)
152+
}
153+
if gotInsert == nil {
154+
t.Fatal("expected insertDimension request")
155+
}
156+
// before-insert defaults inheritFromBefore=false; the explicit flag overrides it.
157+
if !gotInsert.InheritFromBefore {
158+
t.Fatal("expected inheritFromBefore=true when --inherit-from-before is set")
159+
}
160+
})
161+
162+
t.Run("reject inherit from before at first row", func(t *testing.T) {
163+
gotInsert = nil
164+
cmd := &SheetsInsertCmd{}
165+
err := runKong(t, cmd, []string{
166+
"s1", "Data", "rows", "1", "--inherit-from-before",
167+
}, ctx, flags)
168+
if err == nil {
169+
t.Fatal("expected error")
170+
}
171+
if !strings.Contains(err.Error(), "cannot inherit from the previous row") {
172+
t.Fatalf("unexpected error: %v", err)
173+
}
174+
if gotInsert != nil {
175+
t.Fatal("did not expect API request")
176+
}
177+
})
178+
127179
t.Run("insert cols before", func(t *testing.T) {
128180
gotInsert = nil
129181
cmd := &SheetsInsertCmd{}

0 commit comments

Comments
 (0)