4 releases (2 breaking)

0.3.0 Dec 2, 2021
0.2.0 Nov 18, 2021
0.1.1 Mar 13, 2021
0.1.0 Mar 13, 2021

#803 in Configuration

Download history 15/week @ 2024-03-11 10/week @ 2024-03-18 14/week @ 2024-03-25 31/week @ 2024-04-01 14/week @ 2024-04-08 13/week @ 2024-04-15 33/week @ 2024-04-22 17/week @ 2024-04-29 6/week @ 2024-05-06 16/week @ 2024-05-13 97/week @ 2024-05-20 20/week @ 2024-05-27 16/week @ 2024-06-03 15/week @ 2024-06-10 10/week @ 2024-06-17 15/week @ 2024-06-24

59 downloads per month
Used in 3 crates

MIT/Apache

140KB
942 lines

🌐 SSH Cfg

Crates.io docs.rs CI

Parses ~/.ssh/config asynchronously.

use ssh_cfg::{SshConfigParser, SshOptionKey};
use tokio::runtime;

async fn parse_ssh_config() -> Result<(), Box<dyn std::error::Error>> {
    let ssh_config = SshConfigParser::parse_home().await?;

    // Print first host config
    if let Some((first_host, host_config)) = ssh_config.iter().next() {
        println!("Host: {}", first_host);

        // Print its configured SSH key if any
        if let Some(identity_file) = host_config.get(&SshOptionKey::IdentityFile) {
            println!("  {} {}", SshOptionKey::IdentityFile, identity_file);
        }
    }

    // Print all host configs
    println!();
    println!("{:#?}", ssh_config);

    Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rt = runtime::Builder::new_current_thread().build()?;
    rt.block_on(parse_ssh_config())
}

Currently values are stored as Strings. Ideally we would parse them into a strong data model.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.5MB
~39K SLoC