Skip to content

Commit

Permalink
Add default flake and node from environment values
Browse files Browse the repository at this point in the history
Users can set:
DEPLOY_RS_DEFAULT_FLAKE_ROOT
DEPLOY_RS_DEFAULT_NODE

If set, targets that are not paths (starting with '.'|'/') are suffixed
to those defaults.

This affords users a shorthand to their preferred flake [and node]
derived from context.
  • Loading branch information
blaggacao committed Aug 6, 2021
1 parent d721743 commit fc7ab52
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,25 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
deploy::LoggerType::Deploy,
)?;

fn maybe_default_target(target: Option<String>) -> Vec<String> {
match (target, std::env::var("DEPLOY_RS_DEFAULT_FLAKE_ROOT"), std::env::var("DEPLOY_RS_DEFAULT_NODE")) {
(None, _, _) => vec![".".to_string()],
(Some(target), Err(_), _) => vec![target],
(Some(target), Ok(flake_root), Ok(node)) => {
info!("Default node configured: `{}#{}`", &flake_root, &node);
vec![format!("{}#{}.{}", flake_root, node, target)]
},
(Some(target), Ok(flake_root), Err(_)) => {
info!("Default flake configured: `{}`", &flake_root);
vec![format!("{}#{}", flake_root, target)]
},
}
}

let deploys = opts
.clone()
.targets
.unwrap_or_else(|| vec![opts.clone().target.unwrap_or(".".to_string())]);
.unwrap_or_else(|| maybe_default_target(opts.target.clone()));

let deploy_flakes: Vec<DeployFlake> = deploys
.iter()
Expand Down

0 comments on commit fc7ab52

Please sign in to comment.