Skip to content

Commit d1da0e6

Browse files
committed
fix(sheets): validate insert formatting inheritance
1 parent 9777794 commit d1da0e6

4 files changed

Lines changed: 26 additions & 4 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +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 adjacent row/column. Defaults to true with --after, false otherwise; set to false to insert with plain formatting. |
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. |
3535
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
3636
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
3737
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |

internal/cmd/sheets_insert.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type SheetsInsertCmd struct {
2020
After bool `name:"after" help:"Insert after the position instead of before"`
2121
// *bool so an unset flag keeps the historical default (inherit only when
2222
// --after); passing --inherit-from-before[=false] overrides it explicitly.
23-
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."`
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."`
2424
}
2525

2626
func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error {
@@ -67,6 +67,9 @@ func (c *SheetsInsertCmd) Run(ctx context.Context, flags *RootFlags) error {
6767
if c.InheritFromBefore != nil {
6868
inheritFromBefore = *c.InheritFromBefore
6969
}
70+
if inheritFromBefore && startIndex == 0 {
71+
return usagef("cannot inherit from the previous %s when inserting at position 1", dimLabel)
72+
}
7073

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

internal/cmd/sheets_insert_test.go

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

127-
t.Run("insert after without inheriting formatting", func(t *testing.T) {
127+
t.Run("insert after inheriting from following dimension", func(t *testing.T) {
128128
gotInsert = nil
129129
cmd := &SheetsInsertCmd{}
130130
if err := runKong(t, cmd, []string{
@@ -135,7 +135,8 @@ func TestSheetsInsertCmd(t *testing.T) {
135135
if gotInsert == nil {
136136
t.Fatal("expected insertDimension request")
137137
}
138-
// --after would default inheritFromBefore=true; the explicit flag overrides it.
138+
// --after would default inheritFromBefore=true; the explicit flag overrides it
139+
// so the API inherits from the following adjacent row/column instead.
139140
if gotInsert.InheritFromBefore {
140141
t.Fatal("expected inheritFromBefore=false when --inherit-from-before=false overrides --after")
141142
}
@@ -158,6 +159,23 @@ func TestSheetsInsertCmd(t *testing.T) {
158159
}
159160
})
160161

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+
161179
t.Run("insert cols before", func(t *testing.T) {
162180
gotInsert = nil
163181
cmd := &SheetsInsertCmd{}

0 commit comments

Comments
 (0)