Skip to content

Add glob pattern expansion to CLI find search paths and environment directories #354

@karthiknadig

Description

@karthiknadig

Summary

The JSONRPC server expands glob patterns in workspace_directories, environment_directories, and search_paths via expand_glob_patterns() from pet-fs. The CLI find command does not — paths are passed through as-is, meaning quoted glob patterns like '**/.venv' or '/home/user/*/venv' are treated as literal paths and fail.

Current behavior

  • Server: calls expand_glob_patterns() on incoming paths in handle_configure and handle_refresh
  • CLI: create_config() in crates/pet/src/lib.rs passes search_paths directly without glob expansion

Desired behavior

Always call expand_glob_patterns() on search paths and environment directories in create_config(). Since expand_glob_patterns() is a no-op for non-glob paths (returns the literal path), this is safe to apply unconditionally.

Implementation

In crates/pet/src/lib.rs, update create_config():

fn create_config(options: &FindOptions) -> Configuration {
    let mut search_paths = vec![];
    if let Some(dirs) = options.search_paths.clone() {
        search_paths.extend(expand_glob_patterns(&dirs));
    }
    // ... rest of config
    
    config.environment_directories = options.environment_directories.as_ref()
        .map(|dirs| expand_glob_patterns(dirs).into_iter().filter(|p| p.is_dir()).collect());
}

Shell interaction note

Shells expand unquoted globs before the program sees them, so:

  • pet find /home/user/*/venv — shell expands, pet receives literal paths (works fine)
  • pet find '**/.venv' — shell passes literal glob, pet expands it (needs this fix)
  • PET_SEARCH_PATHS='/home/user/*/venv,**/.venv' — env vars aren't shell-expanded, pet must expand (needs this fix)

The env var path is the primary use case for glob support. No need to heavily document glob patterns for CLI positional args.

Files to modify

  • crates/pet/src/lib.rs — add expand_glob_patterns() call in create_config()

Depends on

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions