Skip to content

Commit aa8001f

Browse files
formatting
1 parent 3a69ed6 commit aa8001f

File tree

8 files changed

+37
-31
lines changed

8 files changed

+37
-31
lines changed

src/clean.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,11 @@ fn profiles_in_dir<P: AsRef<Path> + fmt::Debug>(dir: P) -> Vec<PathBuf> {
354354
let path = e.path();
355355

356356
if let Ok(dst) = path.read_link() {
357-
let name = match dst.file_name() {
358-
Some(f) => f.to_string_lossy(),
359-
None => {
360-
warn!("Failed to get filename for {:?}", dst);
361-
continue;
362-
}
357+
let name = if let Some(f) = dst.file_name() {
358+
f.to_string_lossy()
359+
} else {
360+
warn!("Failed to get filename for {:?}", dst);
361+
continue;
363362
};
364363

365364
if GENERATION_REGEX.captures(&name).is_some() {

src/commands.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ impl ElevationStrategy {
5050
pub fn resolve(&self) -> Result<OsString> {
5151
match self {
5252
ElevationStrategy::Auto => Self::choice(),
53-
ElevationStrategy::Prefer(program) => {
54-
which(program).map(|x| x.into_os_string()).or_else(|_| {
53+
ElevationStrategy::Prefer(program) => which(program)
54+
.map(std::path::PathBuf::into_os_string)
55+
.or_else(|_| {
5556
let auto = Self::choice()?;
5657
warn!(
5758
"{} not found. Using {} instead",
5859
program.to_string_lossy(),
5960
auto.to_string_lossy()
6061
);
6162
Ok(auto)
62-
})
63-
}
63+
}),
6464
ElevationStrategy::Force(program) => Ok(program.into()),
6565
}
6666
}
@@ -81,7 +81,7 @@ impl ElevationStrategy {
8181
///
8282
/// The logic for choosing this order is that a person with `doas` installed is more likely
8383
/// to be using it as their main privilege elevation program.
84-
/// `run0` and `pkexec` are preinstalled in any NixOS system with polkit support installed,
84+
/// `run0` and `pkexec` are preinstalled in any `NixOS` system with polkit support installed,
8585
/// so they have been placed lower as it's easier to deactivate sudo than it is to remove
8686
/// `run0`/`pkexec`
8787
///
@@ -304,14 +304,18 @@ impl Command {
304304

305305
// Insert 'env' command to explicitly pass environment variables to the elevated command
306306
cmd = cmd.arg("env");
307-
for arg in self.env_vars.iter().flat_map(|(key, action)| match action {
308-
EnvAction::Set(value) => Some(format!("{key}={value}")),
309-
EnvAction::Preserve => match std::env::var(key) {
310-
Ok(value) => Some(format!("{key}={value}")),
311-
Err(_) => None,
312-
},
313-
EnvAction::Remove => None,
314-
}) {
307+
for arg in self
308+
.env_vars
309+
.iter()
310+
.filter_map(|(key, action)| match action {
311+
EnvAction::Set(value) => Some(format!("{key}={value}")),
312+
EnvAction::Preserve => match std::env::var(key) {
313+
Ok(value) => Some(format!("{key}={value}")),
314+
Err(_) => None,
315+
},
316+
EnvAction::Remove => None,
317+
})
318+
{
315319
cmd = cmd.arg(arg);
316320
}
317321

src/darwin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::path::PathBuf;
44
use color_eyre::eyre::{Context, bail, eyre};
55
use tracing::{debug, warn};
66

7-
use crate::commands::ElevationStrategy;
87
use crate::Result;
98
use crate::commands;
109
use crate::commands::Command;
10+
use crate::commands::ElevationStrategy;
1111
use crate::installable::Installable;
1212
use crate::interface::{DarwinArgs, DarwinRebuildArgs, DarwinReplArgs, DarwinSubcommand, DiffType};
1313
use crate::nixos::toplevel_for;

src/home.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ impl HomeRebuildArgs {
112112
let spec_location =
113113
PathBuf::from(std::env::var("HOME")?).join(".local/share/home-manager/specialisation");
114114

115-
let current_specialisation = match spec_location.to_str() {
116-
Some(s) => std::fs::read_to_string(s).ok(),
117-
None => {
118-
tracing::warn!("spec_location path is not valid UTF-8");
119-
None
120-
}
115+
let current_specialisation = if let Some(s) = spec_location.to_str() {
116+
std::fs::read_to_string(s).ok()
117+
} else {
118+
tracing::warn!("spec_location path is not valid UTF-8");
119+
None
121120
};
122121

123122
let target_specialisation = if self.no_specialisation {

src/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use clap::ValueEnum;
77
use clap::{Args, Parser, Subcommand, builder::Styles};
88
use clap_verbosity_flag::InfoLevel;
99

10-
use crate::commands::ElevationStrategy;
1110
use crate::Result;
1211
use crate::checks::{
1312
DarwinReplFeatures, FeatureRequirements, FlakeFeatures, HomeReplFeatures, LegacyFeatures,
1413
NoFeatures, OsReplFeatures,
1514
};
15+
use crate::commands::ElevationStrategy;
1616
use crate::installable::Installable;
1717

1818
const fn make_style() -> Styles {

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ fn main() -> Result<()> {
4343

4444
let elevation = args
4545
.elevation_program
46-
.map(|program| ElevationStrategy::Prefer(program))
47-
.unwrap_or(ElevationStrategy::Auto);
46+
.map_or(ElevationStrategy::Auto, ElevationStrategy::Prefer);
4847

4948
args.command.run(elevation)
5049
}

src/nixos.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ impl OsBuildVmArgs {
6666
impl OsRebuildArgs {
6767
// final_attr is the attribute of config.system.build.X to evaluate.
6868
#[expect(clippy::cognitive_complexity, clippy::too_many_lines)]
69-
fn rebuild(self, variant: &OsRebuildVariant, final_attr: Option<String>, elevation: ElevationStrategy) -> Result<()> {
69+
fn rebuild(
70+
self,
71+
variant: &OsRebuildVariant,
72+
final_attr: Option<String>,
73+
elevation: ElevationStrategy,
74+
) -> Result<()> {
7075
use OsRebuildVariant::{Boot, Build, BuildVm, Switch, Test};
7176

7277
if self.build_host.is_some() || self.target_host.is_some() {

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub fn get_missing_experimental_features(required_features: &[&str]) -> Result<V
288288
///
289289
/// ```rust
290290
/// use nh::commands::ElevationStrategy;
291-
///
291+
///
292292
/// // Elevate the current process to run as root
293293
/// let elevate: fn(ElevationStrategy) -> ! = nh::util::self_elevate;
294294
/// ```

0 commit comments

Comments
 (0)