Skip to content

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

Open
LeanSheng wants to merge 1 commit intosteipete:mainfrom
LeanSheng:drive-search-scoping
Open

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

Conversation

@LeanSheng
Copy link
Copy Markdown

@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
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.

1 participant