summaryrefslogtreecommitdiffstats
path: root/src/commands/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/util.rs')
-rw-r--r--src/commands/util.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/commands/util.rs b/src/commands/util.rs
index ec99d11..8862c05 100644
--- a/src/commands/util.rs
+++ b/src/commands/util.rs
@@ -10,10 +10,13 @@
use std::path::Path;
-use anyhow::anyhow;
+use anyhow::Error;
+use anyhow::Context;
use anyhow::Result;
+use anyhow::anyhow;
use clap::ArgMatches;
use log::{error, info, trace};
+use regex::Regex;
use tokio::stream::StreamExt;
use crate::config::*;
@@ -132,3 +135,15 @@ fn all_phases_available(pkg: &Package, available_phases: &[PhaseName]) -> Result
Ok(())
}
+
+pub fn mk_package_name_regex(regex: &str) -> Result<Regex> {
+ let mut builder = regex::RegexBuilder::new(regex);
+
+ #[allow(clippy::identity_op)]
+ builder.size_limit(1 * 1024 * 1024); // max size for the regex is 1MB. Should be enough for everyone
+
+ builder
+ .build()
+ .with_context(|| anyhow!("Failed to build regex from '{}'", regex))
+ .map_err(Error::from)
+}