Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satisfy Clippy: Use variables directly in format strings #117

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-mixed-uninlined-format-args = false
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ impl fmt::Display for ErrorWithHint {
}

pub fn print_error(err: AnyErr) {
error!("{}", err);
error!("{err}");
}
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,14 @@ fn get_target_user(username: &str) -> Result<User, ErrorWithHint> {
for uid in 150..=499 {
if get_user_by_uid(uid).is_none() {
hint = format!(
"{} with the command:\n sudo useradd '{}' --uid {} --create-home",
hint, username, uid
"{hint} with the command:\n sudo useradd '{username}' --uid {uid} --create-home"
);
break;
}
}

Err(ErrorWithHint::new(
format!("Unknown user '{}'", username),
format!("Unknown user '{username}'"),
hint,
))
}
Expand Down Expand Up @@ -368,7 +367,7 @@ fn run_machinectl_command(
) -> Result<(), AnyErr> {
let mut args = vec!["shell".to_string()];
args.push(format!("--uid={}", ctx.target_user));
args.extend(envvars.iter().map(|v| format!("-E{}", v)));
args.extend(envvars.iter().map(|v| format!("-E{v}")));
args.push("--".to_string());
args.push(".host".to_string());

Expand Down
15 changes: 7 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ pub fn have_command<P: AsRef<Path>>(exe_name: P) -> bool {

fn report_command_error(err: io::Error, program: &str, args: &[String]) -> ErrorWithHint {
ErrorWithHint::new(
format!("Failed to run {}: {}", program, err),
format!("Failed to run {program}: {err}"),
if err.kind() == ErrorKind::NotFound {
format!("Try installing package that contains command '{}'", program)
format!("Try installing package that contains command '{program}'")
} else {
format!("Complete command: {} {}", program, shell_words::join(args))
format!("Complete command: {program} {}", shell_words::join(args))
},
)
}

/// Exec command (ending the current process) or return error.
pub fn exec_command(program: &str, args: &[String]) -> Result<(), ErrorWithHint> {
debug!("Executing: {} {}", program, shell_words::join(args));
debug!("Executing: {program} {}", shell_words::join(args));
// If this call returns at all, it was an error
let err: io::Error = Command::new(program).args(args).exec();

Expand All @@ -42,7 +42,7 @@ pub fn exec_command(program: &str, args: &[String]) -> Result<(), ErrorWithHint>

/// Run command as subprocess. Return output if status was 0, otherwise return as error.
pub fn run_command(program: &str, args: &[String]) -> Result<Output, ErrorWithHint> {
debug!("Running: {} {}", program, shell_words::join(args));
debug!("Running: {program} {}", shell_words::join(args));
let ret = Command::new(program)
.args(args)
.output()
Expand All @@ -51,12 +51,11 @@ pub fn run_command(program: &str, args: &[String]) -> Result<Output, ErrorWithHi
if !ret.status.success() {
return Err(ErrorWithHint::new(
format!(
"{} returned {}:\n{}",
program,
"{program} returned {}:\n{}",
ret.status.code().unwrap_or(999),
String::from_utf8_lossy(&ret.stderr).trim()
),
format!("Complete command: {} {}", program, shell_words::join(args)),
format!("Complete command: {program} {}", shell_words::join(args)),
));
}
Ok(ret)
Expand Down