Also show working directory on action overview

Fixes #1
This commit is contained in:
Leonard Steppy 2024-12-13 18:09:17 +01:00
parent 80d53e78ca
commit ebb78c3628
2 changed files with 17 additions and 21 deletions

View File

@ -6,12 +6,13 @@ use std::path::PathBuf;
#[derive(Debug)] #[derive(Debug)]
pub struct ServerActions<'a> { pub struct ServerActions<'a> {
pub server: &'a Server, pub server: &'a Server,
pub actions: Vec<FileAction> pub working_directory: PathBuf,
pub actions: Vec<FileAction>,
} }
impl Display for ServerActions<'_> { impl Display for ServerActions<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 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 { for action in &self.actions {
write!(f, "\n{}", action)?; write!(f, "\n{}", action)?;
} }
@ -31,7 +32,12 @@ impl Display for FileAction {
Action::Add => write!(f, "+ adding {}", self.file.to_string_lossy()), Action::Add => write!(f, "+ adding {}", self.file.to_string_lossy()),
Action::Replace => write!(f, "~ replacing {}", 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::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, Add,
Replace, Replace,
Delete, Delete,
Rename { Rename { new_name: OsString },
new_name: OsString,
} }
}

View File

@ -116,12 +116,13 @@ fn main() -> Result<(), String> {
let actions = servers let actions = servers
.iter() .iter()
.map(|server| { .map(|server| {
let working_directory = server.server_directory_path.join(&upload_directory);
Ok(ServerActions { Ok(ServerActions {
server, server,
actions: { actions: {
let output = ShellCmd::new("ssh") let output = ShellCmd::new("ssh")
.arg(&server.ssh_name) .arg(&server.ssh_name)
.arg(osf!("ls ") + server.server_directory_path.join(&upload_directory)) .arg(osf!("ls ") + &working_directory)
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.output() .output()
.map_err(|e| format!("failed to query files via ssh: {e}"))?; .map_err(|e| format!("failed to query files via ssh: {e}"))?;
@ -183,9 +184,10 @@ fn main() -> Result<(), String> {
actions.push(add_action); actions.push(add_action);
} }
actions actions
}, }
} }
}, },
working_directory,
}) })
}) })
.collect::<Result<Vec<_>, String>>()?; .collect::<Result<Vec<_>, String>>()?;
@ -219,11 +221,7 @@ fn main() -> Result<(), String> {
Action::Add | Action::Replace => { Action::Add | Action::Replace => {
ShellCmd::new("scp") ShellCmd::new("scp")
.arg(file.clone()) .arg(file.clone())
.arg( .arg(osf!(&server.ssh_name) + ":" + &server_actions.working_directory)
osf!(&server.ssh_name)
+ ":"
+ server.server_directory_path.join(&upload_directory),
)
.spawn() .spawn()
.map_err(|e| format!("failed to upload file: {e}"))? .map_err(|e| format!("failed to upload file: {e}"))?
.wait() .wait()
@ -232,12 +230,7 @@ fn main() -> Result<(), String> {
Action::Delete => { Action::Delete => {
ShellCmd::new("ssh") ShellCmd::new("ssh")
.arg(&server.ssh_name) .arg(&server.ssh_name)
.arg( .arg(osf!("cd ") + &server_actions.working_directory + "; rm " + &file_action.file)
osf!("cd ")
+ server.server_directory_path.join(&upload_directory)
+ "; rm "
+ &file_action.file,
)
.spawn() .spawn()
.map_err(|e| format!("failed to send delete command: {e}"))? .map_err(|e| format!("failed to send delete command: {e}"))?
.wait() .wait()
@ -248,7 +241,7 @@ fn main() -> Result<(), String> {
.arg(&server.ssh_name) .arg(&server.ssh_name)
.arg( .arg(
osf!("cd ") osf!("cd ")
+ server.server_directory_path.join(&upload_directory) + &server_actions.working_directory
+ "; mv " + "; mv "
+ &file_action.file + &file_action.file
+ " " + " "