1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::cli::{Cli, Commands};
use crate::error::ScpError;
use crate::scp::{Connect, Mode, SshOpts};
use crate::utils::get_private_key_path;
use clap::Parser;
use std::path::PathBuf;

pub async fn run() -> anyhow::Result<(), ScpError> {
    let args = Cli::parse();

    match args.command {
        Commands::Receive {
            source,
            destination,
            host,
            user: username,
            private_key,
            replace,
        } => {
            let private_key = get_private_key_path(&private_key)?;

            let scp_opts = SshOpts {
                host: format!("{}:22", host),
                private_key,
                username,
            };

            let mode = if replace { Mode::Replace } else { Mode::Ignore };

            return Connect::new(scp_opts, mode)?
                .receive(&PathBuf::from(source), &PathBuf::from(destination))
                .await;
        }
    }
}