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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <spreadsheetId> --tab=<name|sheetId> --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 <docId> --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

Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/sheets_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions internal/cmd/sheets_insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
Loading