Skip to content

Commit 9699d78

Browse files
committed
fix targets and build args from clap v4 update
1 parent 6bc76b8 commit 9699d78

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Any "extra" arguments will be passed into the Nix calls, so for instance to depl
2828
You can try out this tool easily with `nix run`:
2929
- `nix run github:serokell/deploy-rs your-flake`
3030

31-
If you want to deploy multiple flakes or a subset of profiles with one invocation, instead of calling `deploy <flake>` you can issue `deploy --targets <flake> [<flake> ...]` where `<flake>` is supposed to take the same format as discussed before.
31+
If you want to deploy multiple flakes or a subset of profiles with one invocation, instead of calling `deploy <flake>` you can add `--target` multiple times. Use shell brace expansion to make this easier: `deploy --target={<flake>,<flake>,...}` where `<flake>` is supposed to take the same format as discussed before. Ex: `--target=.#{host1,host2.system,host3.myuser}`.
3232

3333
Running in this mode, if any of the deploys fails, the deploy will be aborted and all successful deploys rolled back. `--rollback-succeeded false` can be used to override this behavior, otherwise the `auto-rollback` argument takes precedent.
3434

nix/tests/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ in {
171171
non-flake-with-flakes = mkTest {
172172
name = "non-flake-with-flakes";
173173
flakes = true;
174-
deployArgs = "--file . --targets server";
174+
deployArgs = "--file . --target server";
175175
};
176176
}

src/cli.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ use tokio::process::Command;
2323
#[derive(Parser, Debug, Clone)]
2424
#[command(version = "1.0", author = "Serokell <https://serokell.io/>")]
2525
pub struct Opts {
26-
/// The flake to deploy
27-
#[arg(group = "deploy")]
28-
target: Option<String>,
29-
30-
/// A list of flakes to deploy alternatively
31-
#[arg(long, group = "deploy")]
32-
targets: Option<Vec<String>>,
26+
/// A flake to deploy, can be repeated
27+
#[arg(long, action = clap::ArgAction::Append)]
28+
target: Option<Vec<String>>,
3329
/// Treat targets as files instead of flakes
3430
#[clap(short, long)]
3531
file: Option<String>,
@@ -39,9 +35,6 @@ pub struct Opts {
3935
/// Use the interactive prompt before deployment
4036
#[arg(short, long)]
4137
interactive: bool,
42-
/// Extra arguments to be passed to nix build
43-
extra_build_args: Vec<String>,
44-
4538
/// Print debug logs to output
4639
#[arg(short, long)]
4740
debug_logs: bool,
@@ -109,6 +102,15 @@ pub struct Opts {
109102
/// Prompt for sudo password during activation.
110103
#[arg(long)]
111104
interactive_sudo: Option<bool>,
105+
106+
#[command(subcommand)]
107+
command: Option<Passthrough>,
108+
}
109+
110+
#[derive(Parser, Debug, Clone)]
111+
enum Passthrough {
112+
#[clap(external_subcommand)]
113+
Args(Vec<String>),
112114
}
113115

114116
/// Returns if the available Nix installation supports flakes
@@ -607,8 +609,8 @@ async fn run_deploy(
607609
let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
608610

609611
// Run all deployments
610-
// In case of an error rollback any previoulsy made deployment.
611-
// Rollbacks adhere to the global seeting to auto_rollback and secondary
612+
// In case of an error rollback any previously made deployment.
613+
// Rollbacks adhere to the global setting to auto_rollback and secondary
612614
// the profile's configuration
613615
for (_, deploy_data, deploy_defs) in &parts {
614616
if let Err(e) = deploy::deploy::deploy_profile(deploy_data, deploy_defs, dry_activate, boot).await
@@ -620,7 +622,7 @@ async fn run_deploy(
620622
if rollback_succeeded && cmd_overrides.auto_rollback.unwrap_or(true) {
621623
info!("Revoking previous deploys");
622624
// revoking all previous deploys
623-
// (adheres to profile configuration if not set explicitely by
625+
// (adheres to profile configuration if not set explicitly by
624626
// the command line)
625627
for (deploy_data, deploy_defs) in &succeeded {
626628
if deploy_data.merged_settings.auto_rollback.unwrap_or(true) {
@@ -678,9 +680,14 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
678680
}
679681

680682
let deploys = opts
681-
.clone()
682-
.targets
683-
.unwrap_or_else(|| vec![opts.clone().target.unwrap_or_else(|| ".".to_string())]);
683+
.target
684+
.unwrap_or_else(|| vec![".".to_string()]);
685+
686+
let extra_build_args = if let Some(Passthrough::Args(args)) = opts.command {
687+
args
688+
} else {
689+
Vec::new()
690+
};
684691

685692
let deploy_flakes: Vec<DeployFlake> =
686693
if let Some(file) = &opts.file {
@@ -728,11 +735,11 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
728735

729736
if !opts.skip_checks {
730737
for deploy_flake in &deploy_flakes {
731-
check_deployment(using_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
738+
check_deployment(using_flakes, deploy_flake.repo, &extra_build_args).await?;
732739
}
733740
}
734741
let result_path = opts.result_path.as_deref();
735-
let data = get_deployment_data(using_flakes, &deploy_flakes, &opts.extra_build_args).await?;
742+
let data = get_deployment_data(using_flakes, &deploy_flakes, &extra_build_args).await?;
736743
run_deploy(
737744
deploy_flakes,
738745
data,
@@ -742,7 +749,7 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
742749
&cmd_overrides,
743750
opts.keep_result,
744751
result_path,
745-
&opts.extra_build_args,
752+
&extra_build_args,
746753
opts.debug_logs,
747754
opts.dry_activate,
748755
opts.boot,

0 commit comments

Comments
 (0)