You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice that clap handle not only a single RegEx in the validator_regex() function but a RegexSet.
RegexSet are useful to combine multiple regex together and check if any of the regex provided match the string to test.
What I standed for BEFORE validator_regex():
This is what I did in conjunction to validator() function.
use lazy_static::lazy_static;use regex::Regex;pubfnis_hosts(v:&str) -> Result<(),String>{lazy_static!{static ref HOSTNAME_REGEX:Regex = Regex::new(r"(?x) ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]) (\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$ ").unwrap();static ref IP_REGEX:Regex = Regex::new(r"(?x) ^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3} (\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$ ").unwrap();static ref NETINT_REGEX:Regex = Regex::new(r"(?x) ^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3} (\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])/([1-9]|[12]\d|3[012])$ ").unwrap();}matchHOSTNAME_REGEX.is_match(v) || IP_REGEX.is_match(v) || NETINT_REGEX.is_match(v){true => {Ok(())}false => {Err(format!("{} isn't a host nor an ip nor a network interface", v))}}}
What I standed for AFTER validator_regex():
So I would like to do this kind of thing:
//In the module that generate the AppApp::new("...")// [SNIP...].arg(Arg::new(target::NAME).last(true).takes_value(true).value_delimiter(" ").multiple(true)//.validator(validators::net::is_hosts).validator_regex(HOST_REGEXSET,"only hostnames, ip, network intefaces are allowed").required_unless_present_any(&[input_list::NAME, input_random::NAME]).display_order(1))
But RegexRef take a Cow<'a, Regex>, maybe you should refactor this to have RegexSet instead ?
Alternatives, if applicable
The solution I standed before the validator_regex() works fine, I would like to know:
Which one of these both solutions are the most effective ?
Since I am not figuring out yet : How could I use the lazy_static to improve the effectiveness of the regex compilation combining to store it in a constant variable and be reusable further in the code ?
So until there is not an implementation for handling RegexSet I would use the validator and my match pattern 😄 .
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Please complete the following tasks
Clap Version
3.0.0-beta.2
Describe your use case
It would be nice that clap handle not only a single RegEx in the validator_regex() function but a RegexSet.
RegexSet are useful to combine multiple regex together and check if any of the regex provided match the string to test.
What I standed for BEFORE validator_regex():
This is what I did in conjunction to validator() function.
What I standed for AFTER validator_regex():
So I would like to do this kind of thing:
Describe the solution you'd like
I would like a function or an implementation to validate the RegexSet like the validator_regex():
But RegexRef take a Cow<'a, Regex>, maybe you should refactor this to have RegexSet instead ?
Alternatives, if applicable
The solution I standed before the validator_regex() works fine, I would like to know:
Which one of these both solutions are the most effective ?
Since I am not figuring out yet : How could I use the lazy_static to improve the effectiveness of the regex compilation combining to store it in a constant variable and be reusable further in the code ?
So until there is not an implementation for handling RegexSet I would use the validator and my match pattern 😄 .
Additional Context
No response
The text was updated successfully, but these errors were encountered: