replace print calls with log calls
This commit is contained in:
parent
4a3fd978a4
commit
b88fabb725
38
src/main.rs
38
src/main.rs
@ -158,11 +158,7 @@ fn main() -> Result<(), String> {
|
||||
no_confirm,
|
||||
file_name,
|
||||
} => {
|
||||
if servers.is_empty() {
|
||||
println!("Please provide some servers to upload to. See --help");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
require_non_empty_servers(&servers)?;
|
||||
start_ssh_agent()?;
|
||||
|
||||
let file_name_info =
|
||||
@ -248,13 +244,13 @@ fn main() -> Result<(), String> {
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?;
|
||||
|
||||
println!("The following actions will be performed:");
|
||||
log!(logger, "The following actions will be performed: ");
|
||||
for server_actions in &actions {
|
||||
println!("{server_actions}");
|
||||
log!(logger, "{server_actions}");
|
||||
}
|
||||
|
||||
if !no_confirm {
|
||||
print!("Continue? [Y|n] ");
|
||||
log!(logger, "Continue? [Y|n] ");
|
||||
std::io::stdout().flush().expect("failed to flush stdout");
|
||||
let mut buffer = String::new();
|
||||
std::io::stdin()
|
||||
@ -262,7 +258,7 @@ fn main() -> Result<(), String> {
|
||||
.expect("failed to read stdin");
|
||||
match buffer.to_lowercase().trim() {
|
||||
"n" | "no" => {
|
||||
println!("Aborting...");
|
||||
log!(logger, "Aborting...");
|
||||
return Ok(());
|
||||
}
|
||||
_ => {}
|
||||
@ -271,7 +267,7 @@ fn main() -> Result<(), String> {
|
||||
|
||||
for server_actions in actions {
|
||||
let server = server_actions.server;
|
||||
println!("Performing actions on {}...", server.ssh_name);
|
||||
log!(logger, "Performing actions on {}...", server.ssh_name);
|
||||
for file_action in server_actions.actions {
|
||||
match file_action.kind {
|
||||
Action::Add | Action::Replace => {
|
||||
@ -312,12 +308,13 @@ fn main() -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
println!("Done!");
|
||||
log!(logger, "Done!");
|
||||
}
|
||||
Command::Command { command } => {
|
||||
start_ssh_agent()?;
|
||||
require_non_empty_servers(&servers)?;
|
||||
for server in servers {
|
||||
println!("Running command on '{}'...", server.ssh_name);
|
||||
log!(logger, "Running command on '{}'...", server.ssh_name);
|
||||
ShellCmd::new("ssh")
|
||||
.arg(server.ssh_name)
|
||||
.arg(osf!("cd ") + server.server_directory_path + "; " + &command)
|
||||
@ -326,7 +323,7 @@ fn main() -> Result<(), String> {
|
||||
.wait()
|
||||
.map_err(|e| format!("failed to wait for ssh command completion: {e}"))?;
|
||||
}
|
||||
println!("Done!");
|
||||
log!(logger, "Done!");
|
||||
}
|
||||
Command::Editor {
|
||||
file,
|
||||
@ -353,16 +350,17 @@ fn main() -> Result<(), String> {
|
||||
.any(|entry| entry.file_name() == file_name)
|
||||
{
|
||||
return Err(format!(
|
||||
"A file with the name {} already exists in {}. You can override it with --override",
|
||||
"A file with the name {} already exists in {}. You can override it with --override or -f",
|
||||
file_name.to_string_lossy(),
|
||||
working_directory.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
require_non_empty_servers(&servers)?;
|
||||
start_ssh_agent()?;
|
||||
|
||||
for server in servers {
|
||||
println!("Downloading file from {}...", server.ssh_name);
|
||||
log!(logger, "Downloading file from {}...", server.ssh_name);
|
||||
ShellCmd::new("scp")
|
||||
.arg(osf!(&server.ssh_name) + ":" + server.server_directory_path.join(&file))
|
||||
.arg(&working_directory)
|
||||
@ -390,13 +388,21 @@ fn main() -> Result<(), String> {
|
||||
.map_err(|e| format!("failed to upload file again: {e}"))?;
|
||||
}
|
||||
|
||||
println!("Done!");
|
||||
log!(logger, "Done!");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn require_non_empty_servers(servers: &[Server]) -> Result<(), String> {
|
||||
if servers.is_empty() {
|
||||
Err("You did not provide any servers for this operation. Please see --help".to_string())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn start_ssh_agent() -> Result<(), String> {
|
||||
//start the ssh agent
|
||||
let agent_output = ShellCmd::new("ssh-agent")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user