atsh-lib 0.1.6

autossh/@shell library is used to ssh login and allow automatically login without password
Documentation
use crate::atsh::{
    add, add_remote, download, get, get_all, initialize, login, pprint, remove, try_get, upload,
    Remote, CONFIG,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // or initialize("/path/to/data/save").expect("initialize failed");
    // default data path
    initialize(Option::<&std::path::Path>::None)?;
    // set data to $home/.atsh.d
    initialize(std::env::home_dir().map(|h| h.join(".atsh.d")))?;
    // get ATSH_KEY
    let key = CONFIG.get_enc_key()?;
    // set ATSH_KEY
    CONFIG.set_enc_key(Some("secret"))?;
    // or export ATSH_KEY
    unsafe { std::env::set_var("ASKEY", "secret") };
    // clear ATSH_KEY
    CONFIG.set_enc_key(Option::<&str>::None)?;
    // add server info
    add(
        "user",
        "password",
        "ip",
        22,
        &Some("name"),
        &Option::<&str>::None,
    )?;
    // or add remote
    add_remote(&Remote {
        index: 0, // ignore this value, auto increment when insert to database
        user: "user".to_string(),
        password: "password".to_string(),
        ip: "ip".to_string(),
        port: 22,
        authorized: false,
        name: Some("name".to_string()),
        note: Option::<String>::None,
    })?;
    // get all remotes
    let remotes = get_all()?;
    // login by index
    let remote = remotes.get(0).unwrap();
    login(remote.index, false)?;
    // login with reauth,
    // This enforces re-authentication, which can be useful when data is migrated
    login(remote.index, true)?;
    // get remote by index, return Option<Remote>
    let find = get(remote.index)?;
    // get remote by index, return Remote or Error if not found
    let find = try_get(remote.index)?;
    // remove by index
    remove(&vec![remote.index])?;
    // download
    download(
        remote.index,
        &vec!["/path/to/remote/test.txt", "/path/to/host/test.txt"],
    )?;
    // upload
    upload(
        remote.index,
        &vec!["/path/to/local/test.txt", "/path/to/remote/test.txt"],
    )?;
    // pretty print little info
    pprint(false)?;
    // pretty print with all info
    pprint(true)?;
    // create a new ssh key pair
    CONFIG.create_sshkey(
        Option::<&str>::None,
        Option::<&std::path::Path>::None,
        true)?;
    // do something...
    Ok(())
}