Skip to content

feat(drive): add --drive and --parent flags to drive search#525

Closed
LeanSheng wants to merge 1 commit intoopenclaw:mainfrom
LeanSheng:drive-search-scoping
Closed

feat(drive): add --drive and --parent flags to drive search#525
LeanSheng wants to merge 1 commit intoopenclaw:mainfrom
LeanSheng:drive-search-scoping

Conversation

@LeanSheng
Copy link
Copy Markdown
Contributor

@LeanSheng LeanSheng commented Apr 24, 2026

Summary

  • Adds two flags to gog drive search:
    • --drive <driveId> — scopes to a specific shared drive via corpora=drive&driveId=X (the Drive API's proper pattern for recursive within-drive search). Mutually exclusive with --no-all-drives.
    • --parent <folderId> — wraps the query with '<folderId>' in parents, matching drive ls --parent semantics (direct children only, since the Drive API doesn't support recursive parent queries). Mutually exclusive with --raw-query.
  • Extends driveFilesListCallWithDriveSupport with a driveID arg (sole non-test caller, listDriveFiles, passes it through from the new driveFileListOptions.driveID).
  • DriveSearchCmd.Run validates flag combinations up front, before any API call.
  • Default behavior unchanged — no flags means same corpora=allDrives request as before.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./internal/cmd/... -count=1 -timeout 60s (full suite green)
  • Focused run: TestDriveSearchCmd_WithDrive, ..._WithParent, ..._DriveAndParent_Combine, ..._DriveAndNoAllDrives_Conflicts, ..._ParentAndRawQuery_Conflicts — all pass
  • Manual: gog drive search "report" --drive $(gog drive drives --format=json | jq -r '.drives[0].id') returns results from that shared drive only
  • Manual: gog drive search "report" --parent <folderId> returns only direct children of that folder
  • Manual: gog drive search foo --drive X --no-all-drives fails fast with a clear error

Users had no CLI-native way to scope a Drive search to a specific
shared drive or folder. Workarounds required either raw query syntax
(which only matches direct children) or direct API calls bypassing
gog entirely, defeating the purpose of the CLI.

This adds two new flags to 'drive search':

  --drive <driveId>    Scopes search to a specific shared drive using
                       corpora=drive&driveId=X. This is the Drive API's
                       proper pattern for within-drive recursive search.
                       Mutually exclusive with --no-all-drives.

  --parent <folderId>  Wraps the query with "'<folderId>' in parents"
                       to scope results to direct children of a folder
                       (matching 'drive ls --parent' semantics).
                       Mutually exclusive with --raw-query (users with
                       raw queries can include the clause themselves).

Implementation:
  * driveFilesListCallWithDriveSupport takes a new driveID argument;
    when non-empty it sets Corpora("drive").DriveId(X), overriding
    the generic Corpora("allDrives") path.
  * driveFileListOptions gains a driveID field.
  * DriveSearchCmd validates flag combinations up front.

Behavior change:
  * No-args search behavior unchanged — existing users see no change.
  * The sole caller of driveFilesListCallWithDriveSupport passes the
    new driveID from options, preserving current corpora=allDrives
    behavior by default.

Tests added:
  * TestDriveSearchCmd_WithDrive — verifies corpora=drive+driveId wire
  * TestDriveSearchCmd_WithParent — verifies query clause injection
  * TestDriveSearchCmd_DriveAndParent_Combine — verifies the common
    combo of scoping by shared drive + folder works together
  * TestDriveSearchCmd_DriveAndNoAllDrives_Conflicts
  * TestDriveSearchCmd_ParentAndRawQuery_Conflicts
@steipete
Copy link
Copy Markdown
Collaborator

Thanks @LeanSheng. Landed on main as 80039c8, with maintainer cleanup in 617293d.

What changed before landing:

  • kept --drive and --parent for drive search
  • fixed the shared Drive list helper callers used by backup code
  • trimmed/escaped the new ID inputs before passing them into Drive query/API params
  • added changelog credit

Verified:

  • go test ./internal/cmd focused docs/drive suite
  • make ci
  • live smoke on steipete@gmail.com: drive search --parent root found the temp doc, --parent + --raw-query rejected locally, and drive search --drive 0AD1UuQS84YLYUk9PVA exercised the real shared-drive API path

@steipete steipete closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants