colmena/src/main.rs

95 lines
2.8 KiB
Rust
Raw Normal View History

use std::env;
use clap::{App, AppSettings, Arg};
2020-12-15 20:21:26 -08:00
mod nix;
mod command;
mod progress;
mod util;
2020-12-18 01:27:44 -08:00
macro_rules! command {
($module:ident, $matches:ident) => {
if let Some(sub_matches) = $matches.subcommand_matches(stringify!($module)) {
command::$module::run(&$matches, &sub_matches).await;
2020-12-18 01:27:44 -08:00
return;
}
};
($name:expr, $module:ident, $matches:ident) => {
if let Some(sub_matches) = $matches.subcommand_matches($name) {
command::$module::run(&$matches, &sub_matches).await;
return;
}
};
2020-12-18 01:27:44 -08:00
}
macro_rules! bind_command {
($module:ident, $app:ident) => {
$app = $app.subcommand(command::$module::subcommand());
};
2020-12-18 01:27:44 -08:00
}
2021-02-10 10:29:17 -08:00
#[tokio::main]
2020-12-18 01:27:44 -08:00
async fn main() {
init_logging();
2020-12-18 01:27:44 -08:00
let mut app = App::new("Colmena")
2020-12-15 20:21:26 -08:00
.version("0.1.0")
.author("Zhaofeng Li <hello@zhaofeng.li>")
.about("NixOS deployment tool")
.global_setting(AppSettings::ColoredHelp)
.setting(AppSettings::ArgRequiredElseHelp)
.arg(Arg::with_name("config")
.short("f")
.long("config")
2021-01-01 20:45:41 -08:00
.value_name("CONFIG")
.help("Path to a Hive expression")
// The default value is a lie (sort of)!
//
// The default behavior is to search upwards from the
// current working directory for a file named "hive.nix".
// This behavior is disabled if --config/-f is explicitly
// supplied by the user (occurrences_of > 0).
.default_value("hive.nix")
.long_help(r#"If this argument is not specified, Colmena will search upwards from the current working directory for a file named "hive.nix". This behavior is disabled if --config/-f is given explicitly.
For a sample configuration, see <https://github.com/zhaofengli/colmena>.
"#)
.global(true))
.arg(Arg::with_name("show-trace")
.long("show-trace")
.help("Show debug information for Nix commands")
.long_help("Passes --show-trace to Nix commands")
.global(true)
.takes_value(false));
2020-12-15 20:21:26 -08:00
2020-12-18 01:27:44 -08:00
bind_command!(apply, app);
bind_command!(apply_local, app);
2020-12-18 01:27:44 -08:00
bind_command!(build, app);
bind_command!(introspect, app);
bind_command!(upload_keys, app);
2021-02-09 22:07:10 -08:00
bind_command!(exec, app);
2020-12-18 01:27:44 -08:00
let matches = app.clone().get_matches();
2020-12-15 20:21:26 -08:00
2020-12-18 01:27:44 -08:00
command!(apply, matches);
command!("apply-local", apply_local, matches);
2020-12-18 01:27:44 -08:00
command!(build, matches);
command!(introspect, matches);
command!("upload-keys", upload_keys, matches);
2021-02-09 22:07:10 -08:00
command!(exec, matches);
app.print_long_help().unwrap();
2021-03-17 19:03:53 -07:00
println!();
}
fn init_logging() {
if env::var("RUST_LOG").is_err() {
// HACK
env::set_var("RUST_LOG", "info")
}
env_logger::builder()
.format_timestamp(None)
.format_module_path(false)
.init();
2020-12-15 20:21:26 -08:00
}