From ca7be76937f04cc9ae8eeac33201eebf73707221 Mon Sep 17 00:00:00 2001 From: Steppy Date: Wed, 5 Feb 2025 21:19:07 +0100 Subject: [PATCH] Remove minor code duplication --- src/command.rs | 16 +--------------- src/shell_interface.rs | 3 ++- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/command.rs b/src/command.rs index 5636d99..2dfd484 100644 --- a/src/command.rs +++ b/src/command.rs @@ -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::>() - .join(" ") -} - impl Error for CommandSpecificError<'_, E> where E: Debug + Display {} #[derive(Debug)] diff --git a/src/shell_interface.rs b/src/shell_interface.rs index 645e5e9..0e6ff26 100644 --- a/src/shell_interface.rs +++ b/src/shell_interface.rs @@ -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();