Skip to content

Commit

Permalink
Clarify that --ask is meaningless nh ... build or `nh home build …
Browse files Browse the repository at this point in the history
…--dry`.

This could be considered a bug report instead of a PR. I was confused
for a while why nh was ignoring my `--ask`, but then realized I was
doing `nh home build` instead of `nh home switch`.

It seems like `--ask --dry` is valid for `nh darwin`, so it is allowed.
  • Loading branch information
ilyagr committed Jan 15, 2025
1 parent f4da5cf commit 91916f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ impl DarwinArgs {
use DarwinRebuildVariant::*;
match self.subcommand {
DarwinSubcommand::Switch(args) => args.rebuild(Switch),
DarwinSubcommand::Build(args) => args.rebuild(Build),
DarwinSubcommand::Build(args) => {
if args.common.ask || args.common.dry {
bail!("`nh home build` does not support `--ask` or `--dry`");
}
args.rebuild(Build)
}
DarwinSubcommand::Repl(args) => args.run(),
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ impl interface::HomeArgs {
use HomeRebuildVariant::*;
match self.subcommand {
HomeSubcommand::Switch(args) => args.rebuild(Switch),
HomeSubcommand::Build(args) => args.rebuild(Build),
HomeSubcommand::Build(args) => {
if args.common.ask || args.common.dry {
bail!("`nh home build` does not support `--ask` or `--dry`");
}
args.rebuild(Build)
}
HomeSubcommand::Repl(args) => args.run(),
}
}
Expand Down Expand Up @@ -79,6 +84,9 @@ impl HomeRebuildArgs {
}

if self.common.dry || matches!(variant, Build) {
if self.common.ask {
info!("--ask has no effect as dry run was requested");
}
return Ok(());
}

Expand Down
10 changes: 9 additions & 1 deletion src/nixos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ impl interface::OsArgs {
OsSubcommand::Boot(args) => args.rebuild(Boot),
OsSubcommand::Test(args) => args.rebuild(Test),
OsSubcommand::Switch(args) => args.rebuild(Switch),
OsSubcommand::Build(args) => args.rebuild(Build),
OsSubcommand::Build(args) => {
if args.common.ask || args.common.dry {
bail!("`nh os build` does not support `--ask` or `--dry`");
}
args.rebuild(Build)
}
OsSubcommand::Repl(args) => args.run(),
OsSubcommand::Info(args) => args.info(),
}
Expand Down Expand Up @@ -112,6 +117,9 @@ impl OsRebuildArgs {
.run()?;

if self.common.dry || matches!(variant, Build) {
if self.common.ask {
info!("--ask has no effect as dry run was requested");
}
return Ok(());
}

Expand Down

0 comments on commit 91916f4

Please sign in to comment.