From ebb78c3628a9779c385ebeccf1453132708357b9 Mon Sep 17 00:00:00 2001 From: Steppy Date: Fri, 13 Dec 2024 18:09:17 +0100 Subject: [PATCH] Also show working directory on action overview Fixes #1 --- src/action.rs | 17 ++++++++++------- src/main.rs | 21 +++++++-------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/action.rs b/src/action.rs index 3be3237..e7538b5 100644 --- a/src/action.rs +++ b/src/action.rs @@ -6,12 +6,13 @@ use std::path::PathBuf; #[derive(Debug)] pub struct ServerActions<'a> { pub server: &'a Server, - pub actions: Vec + pub working_directory: PathBuf, + pub actions: Vec, } impl Display for ServerActions<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}: ", self.server.ssh_name)?; + write!(f, "{}: ({})", self.server.ssh_name, self.working_directory.to_string_lossy())?; for action in &self.actions { write!(f, "\n{}", action)?; } @@ -31,7 +32,12 @@ impl Display for FileAction { Action::Add => write!(f, "+ adding {}", self.file.to_string_lossy()), Action::Replace => write!(f, "~ replacing {}", self.file.to_string_lossy()), Action::Delete => write!(f, "- deleting {}", self.file.to_string_lossy()), - Action::Rename { new_name } => write!(f, "* renaming {} -> {}", self.file.to_string_lossy(), new_name.to_string_lossy()), + Action::Rename { new_name } => write!( + f, + "* renaming {} -> {}", + self.file.to_string_lossy(), + new_name.to_string_lossy() + ), } } } @@ -41,8 +47,5 @@ pub enum Action { Add, Replace, Delete, - Rename { - new_name: OsString, - } + Rename { new_name: OsString }, } - diff --git a/src/main.rs b/src/main.rs index ebf1d83..8d2d9e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,12 +116,13 @@ fn main() -> Result<(), String> { let actions = servers .iter() .map(|server| { + let working_directory = server.server_directory_path.join(&upload_directory); Ok(ServerActions { server, actions: { let output = ShellCmd::new("ssh") .arg(&server.ssh_name) - .arg(osf!("ls ") + server.server_directory_path.join(&upload_directory)) + .arg(osf!("ls ") + &working_directory) .stdout(Stdio::piped()) .output() .map_err(|e| format!("failed to query files via ssh: {e}"))?; @@ -183,9 +184,10 @@ fn main() -> Result<(), String> { actions.push(add_action); } actions - }, + } } }, + working_directory, }) }) .collect::, String>>()?; @@ -219,11 +221,7 @@ fn main() -> Result<(), String> { Action::Add | Action::Replace => { ShellCmd::new("scp") .arg(file.clone()) - .arg( - osf!(&server.ssh_name) - + ":" - + server.server_directory_path.join(&upload_directory), - ) + .arg(osf!(&server.ssh_name) + ":" + &server_actions.working_directory) .spawn() .map_err(|e| format!("failed to upload file: {e}"))? .wait() @@ -232,12 +230,7 @@ fn main() -> Result<(), String> { Action::Delete => { ShellCmd::new("ssh") .arg(&server.ssh_name) - .arg( - osf!("cd ") - + server.server_directory_path.join(&upload_directory) - + "; rm " - + &file_action.file, - ) + .arg(osf!("cd ") + &server_actions.working_directory + "; rm " + &file_action.file) .spawn() .map_err(|e| format!("failed to send delete command: {e}"))? .wait() @@ -248,7 +241,7 @@ fn main() -> Result<(), String> { .arg(&server.ssh_name) .arg( osf!("cd ") - + server.server_directory_path.join(&upload_directory) + + &server_actions.working_directory + "; mv " + &file_action.file + " "