Remove minor code duplication

This commit is contained in:
Leonard Steppy 2025-02-05 21:19:07 +01:00
parent 6b0b648d67
commit ca7be76937
2 changed files with 3 additions and 16 deletions

View File

@ -1,9 +1,9 @@
use crate::log;
use crate::logger::{LogLevel, Logger};
use crate::shell_interface::command_to_string;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::io;
use std::iter::once;
use std::process::{Command, ExitStatus, Output};
pub trait LogRunnable {
@ -89,20 +89,6 @@ where
}
}
fn command_to_string(command: &Command) -> String {
once(command.get_program().to_string_lossy().to_string())
.chain(command.get_args().map(|arg| {
let arg_str = arg.to_string_lossy();
if arg_str.contains(' ') {
format!("\"{arg_str}\"")
} else {
arg_str.to_string()
}
}))
.collect::<Vec<_>>()
.join(" ")
}
impl<E> Error for CommandSpecificError<'_, E> where E: Debug + Display {}
#[derive(Debug)]

View File

@ -79,7 +79,8 @@ impl Display for ShellCommand {
}
}
fn command_to_string(command: &Command) -> String {
//TODO remove crate visibility once it isn't needed anymore
pub(crate) fn command_to_string(command: &Command) -> String {
once(command.get_program().to_string_lossy().to_string())
.chain(command.get_args().map(|arg| {
let arg_str = arg.to_string_lossy();