diff options
author | notgne2 | 2020-09-29 21:27:49 -0700 |
---|---|---|
committer | notgne2 | 2020-09-29 21:27:49 -0700 |
commit | a0328dbcf76b7c551e92fd25060cfc7d7e4d9ebe (patch) | |
tree | 0d844ad47dbfb259350255e6b0a96f629cd01634 /src/main.rs | |
parent | e3c55575ca6bfd0c9166c52b4aac76b3761bb313 (diff) |
More separation and component testing
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/main.rs b/src/main.rs index 668b697..f8b03a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,7 +143,7 @@ async fn test_flake_support() -> Result<bool, Box<dyn std::error::Error>> { async fn get_deployment_data( supports_flakes: bool, repo: &str, - extra_build_args: Vec<String>, + extra_build_args: &[String], ) -> Result<utils::data::Data, Box<dyn std::error::Error>> { let mut c = match supports_flakes { true => Command::new("nix"), @@ -156,12 +156,12 @@ async fn get_deployment_data( } false => { c - .arg("--strict") - .arg("--read-write-mode") - .arg("--json") - .arg("--eval") - .arg("--E") - .arg(format!("let r = import {}/.; in if builtins.isFunction r then (r {{}}).deploy else r.deploy", repo)) + .arg("--strict") + .arg("--read-write-mode") + .arg("--json") + .arg("--eval") + .arg("--E") + .arg(format!("let r = import {}/.; in if builtins.isFunction r then (r {{}}).deploy else r.deploy", repo)) } }; @@ -186,23 +186,13 @@ async fn get_deployment_data( Ok(serde_json::from_str(&data_json)?) } -#[tokio::main] -async fn main() -> Result<(), Box<dyn std::error::Error>> { - if std::env::var("DEPLOY_LOG").is_err() { - std::env::set_var("DEPLOY_LOG", "info"); - } - - pretty_env_logger::init_custom_env("DEPLOY_LOG"); - - let opts: Opts = Opts::parse(); - - let deploy_flake = utils::parse_flake(opts.flake.as_str()); - - let supports_flakes = test_flake_support().await?; - - let data = - get_deployment_data(supports_flakes, deploy_flake.repo, opts.extra_build_args).await?; +async fn run_deploy( + deploy_flake: utils::DeployFlake<'_>, + data: utils::data::Data, + supports_flakes: bool, + opts: &Opts, +) -> Result<(), Box<dyn std::error::Error>> { match (deploy_flake.node, deploy_flake.profile) { (Some(node_name), Some(profile_name)) => { let node = match data.nodes.get(node_name) { @@ -289,3 +279,24 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) } +#[tokio::main] +async fn main() -> Result<(), Box<dyn std::error::Error>> { + if std::env::var("DEPLOY_LOG").is_err() { + std::env::set_var("DEPLOY_LOG", "info"); + } + + pretty_env_logger::init_custom_env("DEPLOY_LOG"); + + let opts: Opts = Opts::parse(); + + let deploy_flake = utils::parse_flake(opts.flake.as_str()); + + let supports_flakes = test_flake_support().await?; + + let data = + get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?; + + run_deploy(deploy_flake, data, supports_flakes, &opts).await?; + + Ok(()) +} |