Skip to content

Commit e9c496e

Browse files
feat(drive): add read-only reporting commands (#554)
Co-authored-by: Rohan Patnaik <rohan-patnaik@users.noreply.github.com>
1 parent e8e1ac4 commit e9c496e

12 files changed

Lines changed: 833 additions & 3 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Raw API dumps: add `docs raw`, `sheets raw`, `slides raw`, `drive raw`, `gmail raw`, `calendar raw`, `people raw`, `contacts raw`, `tasks raw`, and `forms raw` subcommands for lossless Google API JSON output, with `--pretty`, Drive raw redaction defaults, Sheets grid-data warnings, and a raw-output security audit. (#495, #496) — thanks @karbassi.
99
- Docs: add `docs format` and plain-text `docs write` formatting flags for fonts, colors, bold/italic/underline/strikethrough, alignment, and line spacing. (#479) — thanks @mmaghsoodnia.
1010
- Drive: add `--fields` to `drive ls` and `drive get` so callers can pass Drive API field masks for fields beyond the default JSON set. (#495) — thanks @karbassi.
11+
- Drive: add read-only `drive tree`, `drive du`, and `drive inventory` reports for auditing folder contents and sizes. (#116) — thanks @rohan-patnaik.
1112
- Sheets: add `sheets table` list/get/create/delete commands for Google Sheets structured tables. (#470) — thanks @Pedrohgv.
1213
- Agent safety: add baked safety-profile builds for fail-closed agent binaries, with `agent-safe`, `readonly`, and `full` profiles, filtered help/schema output, docs, and build tooling. (#366, #239) — thanks @drewburchfield.
1314
- Calendar: add `--with-meet` to `calendar update` for adding Google Meet conferencing to existing events. (#538) — thanks @alexisperumal.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Fast, script-friendly CLI for Gmail, Calendar, Chat, Classroom, Drive, Docs, Sli
1313
- **Calendar** - list/create/update/delete events, manage invitations, aliases, subscriptions, team calendars, free/busy/conflicts, propose new times, focus/OOO/working-location events, recurrence, and reminders
1414
- **Classroom** - manage courses, roster, coursework/materials, submissions, announcements, topics, invitations, guardians, profiles
1515
- **Chat** - list/find/create spaces, list messages/threads, send messages and DMs, and manage emoji reactions (Workspace-only)
16-
- **Drive** - list/search/upload/download files, scope search to folders or shared drives, replace uploads in-place, convert uploads (including Markdown to Google Doc), manage permissions/comments, organize folders, and list shared drives
16+
- **Drive** - list/search/upload/download files, inspect folders with tree/du/inventory reports, scope search to folders or shared drives, replace uploads in-place, convert uploads (including Markdown to Google Doc), manage permissions/comments, organize folders, and list shared drives
1717
- **Contacts** - search/create/update contacts, including addresses, relations, org/title metadata, custom fields, Workspace directory, and other contacts
1818
- **Tasks** - manage tasklists and tasks: get/create/add/update/done/undo/delete/clear, plus repeat schedule materialization with RRULE aliases
1919
- **Sheets** - read/write/update spreadsheets, insert rows/cols, manage tabs, named ranges, and Sheets tables, format/merge/freeze/resize cells, manage conditional formatting and banding, read/write notes, inspect formats, find/replace text, list links, and create/export sheets
@@ -1132,6 +1132,12 @@ gog drive get <fileId> # Get file metadata
11321132
gog drive url <fileId> # Print Drive web URL
11331133
gog drive copy <fileId> "Copy Name"
11341134

1135+
# Read-only reports
1136+
gog drive tree --parent <folderId> --depth 2
1137+
gog drive inventory --parent <folderId> --max 500 --sort modified --order desc
1138+
gog drive du --parent <folderId> --depth 1 --max 50
1139+
gog --json drive inventory --parent <folderId> --max 100 | jq '.items[] | {path,size,modifiedTime}'
1140+
11351141
# Upload and download
11361142
gog drive upload ./path/to/file --parent <folderId>
11371143
gog drive upload ./path/to/file --replace <fileId> # Replace file content in-place (preserves shared link)

docs/commands.generated.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ Generated from `gog schema --json`.
245245
- [`gog drive (drv) delete (rm,del) <fileId> [flags]`](commands/gog-drive-delete.md) - Move a file to trash (use --permanent to delete forever)
246246
- [`gog drive (drv) download <fileId> [flags]`](commands/gog-drive-download.md) - Download a file (exports Google Docs formats)
247247
- [`gog drive (drv) drives [flags]`](commands/gog-drive-drives.md) - List shared drives (Team Drives)
248+
- [`gog drive (drv) du [flags]`](commands/gog-drive-du.md) - Summarize Drive folder sizes
248249
- [`gog drive (drv) get <fileId> [flags]`](commands/gog-drive-get.md) - Get file metadata
250+
- [`gog drive (drv) inventory [flags]`](commands/gog-drive-inventory.md) - Export a read-only Drive inventory
249251
- [`gog drive (drv) ls [flags]`](commands/gog-drive-ls.md) - List files in a folder (default: root)
250252
- [`gog drive (drv) mkdir <name> [flags]`](commands/gog-drive-mkdir.md) - Create a folder
251253
- [`gog drive (drv) move <fileId> [flags]`](commands/gog-drive-move.md) - Move a file to a different folder
@@ -254,6 +256,7 @@ Generated from `gog schema --json`.
254256
- [`gog drive (drv) rename <fileId> <newName>`](commands/gog-drive-rename.md) - Rename a file or folder
255257
- [`gog drive (drv) search <query> ... [flags]`](commands/gog-drive-search.md) - Full-text search across Drive
256258
- [`gog drive (drv) share <fileId> [flags]`](commands/gog-drive-share.md) - Share a file or folder
259+
- [`gog drive (drv) tree [flags]`](commands/gog-drive-tree.md) - Print a read-only folder tree
257260
- [`gog drive (drv) unshare <fileId> <permissionId>`](commands/gog-drive-unshare.md) - Remove a permission from a file
258261
- [`gog drive (drv) upload <localPath> [flags]`](commands/gog-drive-upload.md) - Upload a file
259262
- [`gog drive (drv) url <fileId> ...`](commands/gog-drive-url.md) - Print web URLs for files

docs/commands/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Every `gog` command has a generated docs page. The source of truth is the live CLI schema; run `make docs-commands` after changing command names, flags, help text, aliases, or arguments.
44

5-
Generated pages: 466.
5+
Generated pages: 469.
66

77
## Top-level Commands
88

@@ -288,7 +288,9 @@ Generated pages: 466.
288288
- [gog drive delete](gog-drive-delete.md) - Move a file to trash (use --permanent to delete forever)
289289
- [gog drive download](gog-drive-download.md) - Download a file (exports Google Docs formats)
290290
- [gog drive drives](gog-drive-drives.md) - List shared drives (Team Drives)
291+
- [gog drive du](gog-drive-du.md) - Summarize Drive folder sizes
291292
- [gog drive get](gog-drive-get.md) - Get file metadata
293+
- [gog drive inventory](gog-drive-inventory.md) - Export a read-only Drive inventory
292294
- [gog drive ls](gog-drive-ls.md) - List files in a folder (default: root)
293295
- [gog drive mkdir](gog-drive-mkdir.md) - Create a folder
294296
- [gog drive move](gog-drive-move.md) - Move a file to a different folder
@@ -297,6 +299,7 @@ Generated pages: 466.
297299
- [gog drive rename](gog-drive-rename.md) - Rename a file or folder
298300
- [gog drive search](gog-drive-search.md) - Full-text search across Drive
299301
- [gog drive share](gog-drive-share.md) - Share a file or folder
302+
- [gog drive tree](gog-drive-tree.md) - Print a read-only folder tree
300303
- [gog drive unshare](gog-drive-unshare.md) - Remove a permission from a file
301304
- [gog drive upload](gog-drive-upload.md) - Upload a file
302305
- [gog drive url](gog-drive-url.md) - Print web URLs for files

docs/commands/gog-drive-du.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `gog drive du`
2+
3+
> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`.
4+
5+
Summarize Drive folder sizes
6+
7+
## Usage
8+
9+
```bash
10+
gog drive (drv) du [flags]
11+
```
12+
13+
## Parent
14+
15+
- [gog drive](gog-drive.md)
16+
17+
## Flags
18+
19+
| Flag | Type | Default | Help |
20+
| --- | --- | --- | --- |
21+
| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) |
22+
| `-a`<br>`--account`<br>`--acct` | `string` | | Account email for API commands (gmail/calendar/chat/classroom/drive/docs/slides/contacts/tasks/people/sheets/forms/appscript/ads) |
23+
| `--all-drives` | `bool` | true | Include shared drives (default: true; use --no-all-drives for My Drive only) |
24+
| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) |
25+
| `--color` | `string` | auto | Color output: auto\|always\|never |
26+
| `--depth` | `int` | 1 | Depth for folder totals |
27+
| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed |
28+
| `-n`<br>`--dry-run`<br>`--dryrun`<br>`--noop`<br>`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully |
29+
| `--enable-commands` | `string` | | Comma-separated list of enabled commands; dot paths allowed (restricts CLI) |
30+
| `-y`<br>`--force`<br>`--assume-yes`<br>`--yes` | `bool` | | Skip confirmations for destructive commands |
31+
| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) |
32+
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
33+
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
34+
| `--max` | `int` | 50 | Max folders to return (0 = unlimited) |
35+
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
36+
| `--order` | `string` | desc | Sort order |
37+
| `--parent` | `string` | | Folder ID to start from (default: root) |
38+
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
39+
| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) |
40+
| `--select`<br>`--pick`<br>`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. |
41+
| `--sort` | `string` | size | Sort by size\|path\|files |
42+
| `-v`<br>`--verbose` | `bool` | | Enable verbose logging |
43+
| `--version` | `kong.VersionFlag` | | Print version and exit |
44+
45+
## See Also
46+
47+
- [gog drive](gog-drive.md)
48+
- [Command index](README.md)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# `gog drive inventory`
2+
3+
> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`.
4+
5+
Export a read-only Drive inventory
6+
7+
## Usage
8+
9+
```bash
10+
gog drive (drv) inventory [flags]
11+
```
12+
13+
## Parent
14+
15+
- [gog drive](gog-drive.md)
16+
17+
## Flags
18+
19+
| Flag | Type | Default | Help |
20+
| --- | --- | --- | --- |
21+
| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) |
22+
| `-a`<br>`--account`<br>`--acct` | `string` | | Account email for API commands (gmail/calendar/chat/classroom/drive/docs/slides/contacts/tasks/people/sheets/forms/appscript/ads) |
23+
| `--all-drives` | `bool` | true | Include shared drives (default: true; use --no-all-drives for My Drive only) |
24+
| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) |
25+
| `--color` | `string` | auto | Color output: auto\|always\|never |
26+
| `--depth` | `int` | 0 | Max depth (0 = unlimited) |
27+
| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed |
28+
| `-n`<br>`--dry-run`<br>`--dryrun`<br>`--noop`<br>`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully |
29+
| `--enable-commands` | `string` | | Comma-separated list of enabled commands; dot paths allowed (restricts CLI) |
30+
| `-y`<br>`--force`<br>`--assume-yes`<br>`--yes` | `bool` | | Skip confirmations for destructive commands |
31+
| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) |
32+
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
33+
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
34+
| `--max` | `int` | 500 | Max items to return (0 = unlimited) |
35+
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
36+
| `--order` | `string` | asc | Sort order |
37+
| `--parent` | `string` | | Folder ID to start from (default: root) |
38+
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
39+
| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) |
40+
| `--select`<br>`--pick`<br>`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. |
41+
| `--sort` | `string` | path | Sort by path\|size\|modified |
42+
| `-v`<br>`--verbose` | `bool` | | Enable verbose logging |
43+
| `--version` | `kong.VersionFlag` | | Print version and exit |
44+
45+
## See Also
46+
47+
- [gog drive](gog-drive.md)
48+
- [Command index](README.md)

docs/commands/gog-drive-tree.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# `gog drive tree`
2+
3+
> Generated from `gog schema --json`. Do not edit this page by hand; run `make docs-commands`.
4+
5+
Print a read-only folder tree
6+
7+
## Usage
8+
9+
```bash
10+
gog drive (drv) tree [flags]
11+
```
12+
13+
## Parent
14+
15+
- [gog drive](gog-drive.md)
16+
17+
## Flags
18+
19+
| Flag | Type | Default | Help |
20+
| --- | --- | --- | --- |
21+
| `--access-token` | `string` | | Use provided access token directly (bypasses stored refresh tokens; token expires in ~1h) |
22+
| `-a`<br>`--account`<br>`--acct` | `string` | | Account email for API commands (gmail/calendar/chat/classroom/drive/docs/slides/contacts/tasks/people/sheets/forms/appscript/ads) |
23+
| `--all-drives` | `bool` | true | Include shared drives (default: true; use --no-all-drives for My Drive only) |
24+
| `--client` | `string` | | OAuth client name (selects stored credentials + token bucket) |
25+
| `--color` | `string` | auto | Color output: auto\|always\|never |
26+
| `--depth` | `int` | 2 | Max depth (0 = unlimited) |
27+
| `--disable-commands` | `string` | | Comma-separated list of disabled commands; dot paths allowed |
28+
| `-n`<br>`--dry-run`<br>`--dryrun`<br>`--noop`<br>`--preview` | `bool` | | Do not make changes; print intended actions and exit successfully |
29+
| `--enable-commands` | `string` | | Comma-separated list of enabled commands; dot paths allowed (restricts CLI) |
30+
| `-y`<br>`--force`<br>`--assume-yes`<br>`--yes` | `bool` | | Skip confirmations for destructive commands |
31+
| `--gmail-no-send` | `bool` | false | Block Gmail send operations (agent safety) |
32+
| `-h`<br>`--help` | `kong.helpFlag` | | Show context-sensitive help. |
33+
| `-j`<br>`--json`<br>`--machine` | `bool` | false | Output JSON to stdout (best for scripting) |
34+
| `--max` | `int` | 0 | Max items to return (0 = unlimited) |
35+
| `--no-input`<br>`--non-interactive`<br>`--noninteractive` | `bool` | | Never prompt; fail instead (useful for CI) |
36+
| `--parent` | `string` | | Folder ID to start from (default: root) |
37+
| `-p`<br>`--plain`<br>`--tsv` | `bool` | false | Output stable, parseable text to stdout (TSV; no colors) |
38+
| `--results-only` | `bool` | | In JSON mode, emit only the primary result (drops envelope fields like nextPageToken) |
39+
| `--select`<br>`--pick`<br>`--project` | `string` | | In JSON mode, select comma-separated fields (best-effort; supports dot paths). Desire path: use --fields for most commands. |
40+
| `-v`<br>`--verbose` | `bool` | | Enable verbose logging |
41+
| `--version` | `kong.VersionFlag` | | Print version and exit |
42+
43+
## See Also
44+
45+
- [gog drive](gog-drive.md)
46+
- [Command index](README.md)

docs/commands/gog-drive.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ gog drive (drv) <command> [flags]
2121
- [gog drive delete](gog-drive-delete.md) - Move a file to trash (use --permanent to delete forever)
2222
- [gog drive download](gog-drive-download.md) - Download a file (exports Google Docs formats)
2323
- [gog drive drives](gog-drive-drives.md) - List shared drives (Team Drives)
24+
- [gog drive du](gog-drive-du.md) - Summarize Drive folder sizes
2425
- [gog drive get](gog-drive-get.md) - Get file metadata
26+
- [gog drive inventory](gog-drive-inventory.md) - Export a read-only Drive inventory
2527
- [gog drive ls](gog-drive-ls.md) - List files in a folder (default: root)
2628
- [gog drive mkdir](gog-drive-mkdir.md) - Create a folder
2729
- [gog drive move](gog-drive-move.md) - Move a file to a different folder
@@ -30,6 +32,7 @@ gog drive (drv) <command> [flags]
3032
- [gog drive rename](gog-drive-rename.md) - Rename a file or folder
3133
- [gog drive search](gog-drive-search.md) - Full-text search across Drive
3234
- [gog drive share](gog-drive-share.md) - Share a file or folder
35+
- [gog drive tree](gog-drive-tree.md) - Print a read-only folder tree
3336
- [gog drive unshare](gog-drive-unshare.md) - Remove a permission from a file
3437
- [gog drive upload](gog-drive-upload.md) - Upload a file
3538
- [gog drive url](gog-drive-url.md) - Print web URLs for files

internal/cmd/drive.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var (
3333
)
3434

3535
const (
36+
driveRootID = "root"
37+
driveMimeFolder = "application/vnd.google-apps.folder"
3638
driveMimeGoogleDoc = "application/vnd.google-apps.document"
3739
driveMimeGoogleSheet = "application/vnd.google-apps.spreadsheet"
3840
driveMimeGoogleSlides = "application/vnd.google-apps.presentation"
@@ -70,6 +72,9 @@ const (
7072
type DriveCmd struct {
7173
Ls DriveLsCmd `cmd:"" name:"ls" help:"List files in a folder (default: root)"`
7274
Search DriveSearchCmd `cmd:"" name:"search" help:"Full-text search across Drive"`
75+
Tree DriveTreeCmd `cmd:"" name:"tree" help:"Print a read-only folder tree"`
76+
Du DriveDuCmd `cmd:"" name:"du" help:"Summarize Drive folder sizes"`
77+
Inventory DriveInventoryCmd `cmd:"" name:"inventory" help:"Export a read-only Drive inventory"`
7378
Get DriveGetCmd `cmd:"" name:"get" help:"Get file metadata"`
7479
Download DriveDownloadCmd `cmd:"" name:"download" help:"Download a file (exports Google Docs formats)"`
7580
Copy DriveCopyCmd `cmd:"" name:"copy" help:"Copy a file"`
@@ -945,7 +950,7 @@ func escapeDriveQueryString(s string) string {
945950
}
946951

947952
func driveType(mimeType string) string {
948-
if mimeType == "application/vnd.google-apps.folder" {
953+
if mimeType == driveMimeFolder {
949954
return "folder"
950955
}
951956
return strFile

0 commit comments

Comments
 (0)