pub struct PatternResolver { /* private fields */ }Expand description
Resolves pattern-based dependencies to concrete file paths.
The PatternResolver provides advanced pattern matching with exclusion
support and deterministic ordering. It’s designed for resolving
pattern-based dependencies in AGPM manifests to concrete resource files.
§Features
- Exclusion Patterns: Support for excluding specific patterns from results
- Deterministic Ordering: Results are always returned in sorted order
- Deduplication: Automatically removes duplicate paths from results
- Multiple Pattern Support: Can resolve multiple patterns in one operation
§Examples
use agpm_cli::pattern::PatternResolver;
use std::path::Path;
let mut resolver = PatternResolver::new();
// Add exclusion patterns
resolver.exclude("**/test_*.md")?;
resolver.exclude("**/.*")?; // Exclude hidden files
// Resolve pattern with exclusions applied
let matches = resolver.resolve("**/*.md", Path::new("/repo"))?;
println!("Found {} files (excluding test files and hidden files)", matches.len());Implementations§
Source§impl PatternResolver
impl PatternResolver
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new pattern resolver with no exclusions.
The resolver starts with an empty exclusion list. Use exclude
to add patterns that should be filtered out of results.
§Examples
use agpm_cli::pattern::PatternResolver;
let resolver = PatternResolver::new();
// PatternResolver starts with no exclusionsSourcepub fn exclude(&mut self, pattern: &str) -> Result<()>
pub fn exclude(&mut self, pattern: &str) -> Result<()>
Adds an exclusion pattern to filter out unwanted results.
Files matching exclusion patterns will be removed from resolution results. Exclusions are applied after the main pattern matching, making them useful for filtering out test files, hidden files, or other unwanted resources.
§Arguments
pattern- A glob pattern for files to exclude
§Errors
Returns an error if the exclusion pattern is invalid glob syntax.
§Examples
use agpm_cli::pattern::PatternResolver;
let mut resolver = PatternResolver::new();
// Exclude test files
resolver.exclude("**/test_*.md")?;
resolver.exclude("**/*_test.md")?;
// Exclude hidden files
resolver.exclude("**/.*")?;
// Exclude backup files
resolver.exclude("**/*.bak")?;
resolver.exclude("**/*~")?;Sourcepub fn resolve(&self, pattern: &str, base_path: &Path) -> Result<Vec<PathBuf>>
pub fn resolve(&self, pattern: &str, base_path: &Path) -> Result<Vec<PathBuf>>
Resolves a pattern to a list of resource paths with exclusions applied.
This is the primary method for pattern resolution. It finds all files matching the pattern, applies exclusion filters, removes duplicates, and returns results in deterministic sorted order.
§Algorithm
- Use
PatternMatcherto find all files matching the pattern - Filter out any files matching exclusion patterns
- Remove duplicates (though unlikely with file paths)
- Sort results for deterministic ordering
§Arguments
pattern- The glob pattern to match files againstbase_path- The directory to search within
§Returns
A vector of PathBuf objects representing matching files,
sorted in lexicographic order for deterministic results.
§Errors
Returns an error if:
- The pattern is invalid glob syntax
- The base path doesn’t exist or can’t be accessed
- I/O errors occur during directory traversal
§Examples
use agpm_cli::pattern::PatternResolver;
use std::path::Path;
let mut resolver = PatternResolver::new();
resolver.exclude("**/test_*.md")?;
let matches = resolver.resolve("agents/*.md", Path::new("/repo"))?;
for path in &matches {
println!("Agent: {}", path.display());
}Sourcepub fn resolve_multiple(
&self,
patterns: &[String],
base_path: &Path,
) -> Result<Vec<PathBuf>>
pub fn resolve_multiple( &self, patterns: &[String], base_path: &Path, ) -> Result<Vec<PathBuf>>
Resolves multiple patterns and returns unique results.
This method combines results from multiple pattern resolutions, automatically deduplicating any files that match multiple patterns. Useful for installing resources from multiple pattern-based dependencies.
§Arguments
patterns- A slice of pattern strings to resolvebase_path- The directory to search within
§Returns
A vector of unique PathBuf objects representing all files that
match any of the provided patterns, sorted for deterministic results.
§Errors
Returns an error if any pattern is invalid or if directory access fails.
§Examples
use agpm_cli::pattern::PatternResolver;
use std::path::Path;
let resolver = PatternResolver::new();
let patterns = vec![
"agents/*.md".to_string(),
"helpers/*.md".to_string(),
"tools/*.md".to_string(),
];
let matches = resolver.resolve_multiple(&patterns, Path::new("/repo"))?;
println!("Found {} unique resources", matches.len());Trait Implementations§
Auto Trait Implementations§
impl Freeze for PatternResolver
impl RefUnwindSafe for PatternResolver
impl Send for PatternResolver
impl Sync for PatternResolver
impl Unpin for PatternResolver
impl UnwindSafe for PatternResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more