Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glob!: Add three-arg version to specify base_path #347

Merged
merged 1 commit into from Feb 15, 2023

Conversation

the-kenny
Copy link
Contributor

The new three-arg glob! allows users to specify the base directory the glob is working against. This works around the limitation that blobs like ../foo/*.json do not resolve with the current walkdir + globset implementation.

This allows the usage of glob! in nested situations where the globbed files are in a parent directory:

src
├── main.rs
├── snapshots
│   └── insta_glob_test__insta_glob_dir.snap
├── submod
│   └── mod.rs -- glob! tests are here
└── test_data
    └── foo.json
glob!("../test_data", "*.json", |path| { ... })

The new three-arg glob! allows users to specify the base directory the
glob is working against. This works around the limitation that blobs
like `../foo/*.json` do not resolve with the current walkdir + globset
implementation.
@the-kenny
Copy link
Contributor Author

Note that this implementation could provide a nicer interface where glob! or glob_exec would accept a glob like ../test_data/*.json. However, implementation of this isn't as easy as I hoped as we would need to detect & split the path elements from the glob elements (i.E. ../test_data/*.json -> ("../test_data/", "*.json")).

I can tackle this if you prefer this simpler interface.

@mitsuhiko
Copy link
Owner

This looks good to me. Thank you!

@mitsuhiko mitsuhiko merged commit 9d70fac into mitsuhiko:master Feb 15, 2023
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.

None yet

2 participants