Skip to content

feat(drive): add search command #63

@rianjs

Description

@rianjs

Summary

Add gro drive search command to search files by content, name, type, owner, and date.

Usage

gro drive search "quarterly report"           # Full-text search
gro drive search --name "budget"              # Search by filename only
gro drive search --type spreadsheet           # Filter by type
gro drive search --owner me                   # Files I own
gro drive search --owner john@example.com     # Files owned by specific user
gro drive search --modified-after 2024-01-01  # Modified after date
gro drive search --in-folder <folder-id>      # Search within folder
gro drive search "budget" --type document --max 20 --json

Flags

Flag Short Default Description
--name -n - Search filename only (not content)
--type -t - Filter by type
--owner - - Filter by owner ("me" or email)
--modified-after - - Modified after date (YYYY-MM-DD)
--modified-before - - Modified before date (YYYY-MM-DD)
--in-folder - - Search within specific folder
--max -m 25 Maximum results
--json -j false Output as JSON

Implementation

Files to Create/Modify

  • internal/cmd/drive/search.go - Search command implementation
  • internal/cmd/drive/search_test.go - Unit tests
  • internal/cmd/drive/drive.go - Register search subcommand

Drive API Query Building

// Full-text content search
q := "fullText contains 'quarterly report'"

// Filename only search
q := "name contains 'budget'"

// Combined filters
q := "fullText contains 'report' and mimeType = 'application/vnd.google-apps.document' and 'me' in owners"

// Date filters
q += " and modifiedTime > '2024-01-01T00:00:00'"

// Folder scope
q += " and '<folder-id>' in parents"

// Always exclude trash
q += " and trashed = false"

Query Operator Reference

Operator Example Description
fullText contains fullText contains 'hello' Search content
name contains name contains 'report' Search filename
mimeType = mimeType = '...' Exact type match
'email' in owners 'me' in owners Owner filter
modifiedTime > modifiedTime > '2024-01-01' Date comparison

Text Output Format

Found 3 files matching "quarterly report":

ID              NAME                    TYPE         MODIFIED      OWNER
1abc2def3gh     Q4 Quarterly Report     Document     2024-01-15    me
4ijk5lmn6op     Quarterly Budget        Spreadsheet  2024-01-14    john@example.com
7qrs8tuv9wx     Q3 Quarterly Review     Document     2023-10-01    me

Acceptance Criteria

  • Full-text search works
  • Filename-only search works with --name
  • Type filtering works
  • Owner filtering works (both "me" and email)
  • Date filtering works
  • Folder scoping works
  • Filters can be combined
  • JSON output works
  • make verify passes

Blocked By

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions