Fetch User Keys - simple tool for fetching SSH keys from various sources
1use simple_eyre::eyre::Result; 2use clap::Parser; 3use std::path::Path; 4use tokio::fs::File; 5use tokio::io::{self, AsyncReadExt}; 6 7#[derive(Debug, Clone)] 8enum Input { 9 File(Box<Path>), 10 Stdio, 11} 12 13impl<'a> From<&'a str> for Input { 14 fn from(input: &'a str) -> Self { 15 match input { 16 "-" => Input::Stdio, 17 other => Input::File(Path::new(other).into()), 18 } 19 } 20} 21 22impl Input { 23 async fn read_all(&self) -> io::Result<String> { 24 let mut buffer = String::new(); 25 let result = match *self { 26 Input::Stdio => io::stdin().read_to_string(&mut buffer).await, 27 Input::File(ref path) => { 28 let mut f = File::open(path).await?; 29 f.read_to_string(&mut buffer).await 30 } 31 }; 32 33 result.map(|_| buffer) 34 } 35} 36 37#[derive(Debug, Parser)] 38struct Args { 39 #[arg(long, default_value_t = fuk::output::Format::JSONPretty)] 40 format: fuk::output::Format, 41 /// File containing list of keys to be fetched 42 #[arg(value_hint = clap::ValueHint::FilePath)] 43 file: Input, 44} 45 46#[tokio::main] 47async fn main() -> Result<()> { 48 let args = Args::parse(); 49 50 let config: fuk::config::Config = toml::from_str(&args.file.read_all().await?)?; 51 52 let output = fuk::fuk(config).await; 53 54 println!("{}", args.format.render(&output)); 55 56 Ok(()) 57}