fast_scp/
run.rs

1use crate::cli::{Cli, Commands};
2use crate::error::ScpError;
3use crate::scp::{Connect, Mode, SshOpts};
4use crate::utils::get_private_key_path;
5use clap::Parser;
6use std::path::PathBuf;
7
8pub async fn run() -> anyhow::Result<(), ScpError> {
9    let args = Cli::parse();
10
11    match args.command {
12        Commands::Receive {
13            source,
14            destination,
15            host,
16            user: username,
17            private_key,
18            replace,
19        } => {
20            let private_key = get_private_key_path(&private_key)?;
21
22            let scp_opts = SshOpts {
23                host: format!("{}:22", host),
24                private_key,
25                username,
26            };
27
28            let mode = if replace { Mode::Replace } else { Mode::Ignore };
29
30            return Connect::new(scp_opts, mode)?
31                .receive(&PathBuf::from(source), &PathBuf::from(destination))
32                .await;
33        }
34    }
35}