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