colmena/src/command/build.rs

46 lines
1.4 KiB
Rust
Raw Normal View History

2020-12-16 05:21:26 +01:00
use clap::{Arg, App, SubCommand, ArgMatches};
use crate::util;
pub fn subcommand() -> App<'static, 'static> {
let command = SubCommand::with_name("build")
.about("Build the configuration")
.arg(Arg::with_name("verbose")
.short("v")
.long("verbose")
.help("Be verbose")
.long_help("Deactivates the progress spinner and prints every line of output.")
.takes_value(false));
2020-12-29 06:35:43 +01:00
util::register_selector_args(command)
2020-12-16 05:21:26 +01:00
}
pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
let mut hive = util::hive_from_args(local_args).unwrap();
2020-12-16 05:21:26 +01:00
log::info!("Enumerating nodes...");
2020-12-18 10:27:44 +01:00
let all_nodes = hive.deployment_info().await.unwrap();
2020-12-16 05:21:26 +01:00
let selected_nodes = match local_args.value_of("on") {
Some(filter) => {
util::filter_nodes(&all_nodes, filter)
}
2020-12-18 10:27:44 +01:00
None => all_nodes.keys().cloned().collect(),
2020-12-16 05:21:26 +01:00
};
if selected_nodes.len() == 0 {
log::warn!("No hosts matched. Exiting...");
2020-12-18 10:27:44 +01:00
quit::with_code(2);
2020-12-16 05:21:26 +01:00
}
if selected_nodes.len() == all_nodes.len() {
log::info!("Building all node configurations...");
2020-12-16 05:21:26 +01:00
} else {
log::info!("Selected {} out of {} hosts. Building node configurations...", selected_nodes.len(), all_nodes.len());
2020-12-16 05:21:26 +01:00
}
hive.build_selected(selected_nodes).await.unwrap();
log::info!("Success!");
2020-12-16 05:21:26 +01:00
}