Skip to content

Commit fc7ab52

Browse files
committed
Add default flake and node from environment values
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.
1 parent d721743 commit fc7ab52

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/cli.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,25 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
619619
deploy::LoggerType::Deploy,
620620
)?;
621621

622+
fn maybe_default_target(target: Option<String>) -> Vec<String> {
623+
match (target, std::env::var("DEPLOY_RS_DEFAULT_FLAKE_ROOT"), std::env::var("DEPLOY_RS_DEFAULT_NODE")) {
624+
(None, _, _) => vec![".".to_string()],
625+
(Some(target), Err(_), _) => vec![target],
626+
(Some(target), Ok(flake_root), Ok(node)) => {
627+
info!("Default node configured: `{}#{}`", &flake_root, &node);
628+
vec![format!("{}#{}.{}", flake_root, node, target)]
629+
},
630+
(Some(target), Ok(flake_root), Err(_)) => {
631+
info!("Default flake configured: `{}`", &flake_root);
632+
vec![format!("{}#{}", flake_root, target)]
633+
},
634+
}
635+
}
636+
622637
let deploys = opts
623638
.clone()
624639
.targets
625-
.unwrap_or_else(|| vec![opts.clone().target.unwrap_or(".".to_string())]);
640+
.unwrap_or_else(|| maybe_default_target(opts.target.clone()));
626641

627642
let deploy_flakes: Vec<DeployFlake> = deploys
628643
.iter()

0 commit comments

Comments
 (0)