Skip to content

Commit

Permalink
fix: honor extglob for expansion transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno committed Dec 9, 2024
1 parent 45e672c commit e99c137
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 8 additions & 1 deletion brush-core/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ impl<'a> WordExpander<'a> {
word: &Option<String>,
) -> Result<Option<patterns::Pattern>, error::Error> {
if let Some(word) = word {
Ok(Some(self.basic_expand_pattern(word).await?))
let pattern = self
.basic_expand_pattern(word)
.await?
.set_extended_globbing(self.parser_options.enable_extended_globbing);

Ok(Some(pattern))
} else {
Ok(None)
}
Expand Down Expand Up @@ -810,6 +815,7 @@ impl<'a> WordExpander<'a> {
} => {
let expanded_parameter = self.expand_parameter(&parameter, indirect).await?;
let expanded_pattern = self.basic_expand_opt_pattern(&pattern).await?;

transform_expansion(expanded_parameter, |s| {
patterns::remove_smallest_matching_prefix(s.as_str(), &expanded_pattern)
.map(|s| s.to_owned())
Expand All @@ -822,6 +828,7 @@ impl<'a> WordExpander<'a> {
} => {
let expanded_parameter = self.expand_parameter(&parameter, indirect).await?;
let expanded_pattern = self.basic_expand_opt_pattern(&pattern).await?;

transform_expansion(expanded_parameter, |s| {
patterns::remove_largest_matching_prefix(s.as_str(), &expanded_pattern)
.map(|s| s.to_owned())
Expand Down
4 changes: 0 additions & 4 deletions brush-core/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ fn pattern_to_regex_str(
///
/// * `s` - The string to remove the prefix from.
/// * `pattern` - The pattern to match.
/// * `enable_extended_globbing` - Whether or not to enable extended globbing (extglob).
#[allow(clippy::ref_option)]
pub(crate) fn remove_largest_matching_prefix<'a>(
s: &'a str,
Expand All @@ -405,7 +404,6 @@ pub(crate) fn remove_largest_matching_prefix<'a>(
///
/// * `s` - The string to remove the prefix from.
/// * `pattern` - The pattern to match.
/// * `enable_extended_globbing` - Whether or not to enable extended globbing (extglob).
#[allow(clippy::ref_option)]
pub(crate) fn remove_smallest_matching_prefix<'a>(
s: &'a str,
Expand All @@ -428,7 +426,6 @@ pub(crate) fn remove_smallest_matching_prefix<'a>(
///
/// * `s` - The string to remove the suffix from.
/// * `pattern` - The pattern to match.
/// * `enable_extended_globbing` - Whether or not to enable extended globbing (extglob).
#[allow(clippy::ref_option)]
pub(crate) fn remove_largest_matching_suffix<'a>(
s: &'a str,
Expand All @@ -451,7 +448,6 @@ pub(crate) fn remove_largest_matching_suffix<'a>(
///
/// * `s` - The string to remove the suffix from.
/// * `pattern` - The pattern to match.
/// * `enable_extended_globbing` - Whether or not to enable extended globbing (extglob).
#[allow(clippy::ref_option)]
pub(crate) fn remove_smallest_matching_suffix<'a>(
s: &'a str,
Expand Down

0 comments on commit e99c137

Please sign in to comment.