colmena/src/command/build.rs

47 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::nix::Hive;
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<'_>) {
2020-12-29 06:35:43 +01:00
let mut hive = Hive::from_args(local_args).unwrap();
2020-12-16 05:21:26 +01:00
println!("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 {
println!("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() {
println!("Building all node configurations...");
} else {
2020-12-18 10:27:44 +01:00
println!("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();
println!("Success!");
}