forked from DGNum/colmena
Parse value for NodeFilter
with clap
This commit is contained in:
parent
21df0ac5a5
commit
1e38582451
2 changed files with 12 additions and 7 deletions
|
@ -172,11 +172,7 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
|
|||
let goal_arg = local_args.get_one::<String>("goal").unwrap();
|
||||
let goal = Goal::from_str(goal_arg).unwrap();
|
||||
|
||||
// FIXME: Just get_one::<NodeFilter>
|
||||
let filter = local_args
|
||||
.get_one::<String>("on")
|
||||
.map(NodeFilter::new)
|
||||
.transpose()?;
|
||||
let filter = local_args.get_one::<NodeFilter>("on");
|
||||
|
||||
if filter.is_none() && goal != Goal::Build {
|
||||
// User did not specify node, we should check meta and see rules
|
||||
|
@ -189,7 +185,7 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
|
|||
}
|
||||
|
||||
let targets = hive
|
||||
.select_nodes(filter, ssh_config, goal.requires_target_host())
|
||||
.select_nodes(filter.cloned(), ssh_config, goal.requires_target_host())
|
||||
.await?;
|
||||
let n_targets = targets.len();
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
use std::collections::HashSet;
|
||||
use std::convert::AsRef;
|
||||
use std::iter::{FromIterator, Iterator};
|
||||
use std::str::FromStr;
|
||||
|
||||
use glob::Pattern as GlobPattern;
|
||||
|
||||
use super::{ColmenaError, ColmenaResult, NodeConfig, NodeName};
|
||||
|
||||
/// A node filter containing a list of rules.
|
||||
#[derive(Clone)]
|
||||
pub struct NodeFilter {
|
||||
rules: Vec<Rule>,
|
||||
}
|
||||
|
@ -16,7 +18,7 @@ pub struct NodeFilter {
|
|||
/// A filter rule.
|
||||
///
|
||||
/// The filter rules are OR'd together.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
enum Rule {
|
||||
/// Matches a node's attribute name.
|
||||
MatchName(GlobPattern),
|
||||
|
@ -25,6 +27,13 @@ enum Rule {
|
|||
MatchTag(GlobPattern),
|
||||
}
|
||||
|
||||
impl FromStr for NodeFilter {
|
||||
type Err = ColmenaError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Self::new(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeFilter {
|
||||
/// Creates a new filter using an expression passed using `--on`.
|
||||
pub fn new<S: AsRef<str>>(filter: S) -> ColmenaResult<Self> {
|
||||
|
|
Loading…
Reference in a new issue