Something went wrong. Try again.
Fetch User Keys - simple tool for fetching SSH keys from various sources
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465// SPDX-FileCopyrightText: 2024 Łukasz Niemier <#@hauleth.dev>//// SPDX-License-Identifier: EUPL-1.2
use clap::Parser;use simple_eyre::eyre::Result;use std::fs::File;use std::io::{self, prelude::*};use std::path::{Path, PathBuf};
#[derive(Debug, Clone)]enum Input { File(PathBuf), Stdio,}
impl<'a> From<&'a str> for Input { fn from(input: &'a str) -> Self { match input { "-" => Input::Stdio, other => Input::File(Path::new(other).into()), } }}
impl Input { fn read_all(&self) -> io::Result<String> { let mut buffer = String::new(); let result = match *self { Input::Stdio => io::stdin().read_to_string(&mut buffer), Input::File(ref path) => { let mut f = File::open(path)?; f.read_to_string(&mut buffer) } };
result.map(|_| buffer) }}
#[derive(Debug, Parser)]#[command(version, about)]struct Args { /// Output format type #[arg(long, default_value_t = fuk::output::Format::JSON)] format: fuk::output::Format, /// File containing list of keys to be fetched #[arg(value_hint = clap::ValueHint::FilePath)] file: Input,}
fn main() -> Result<()> { let args = Args::parse();
let config: fuk::config::Config = toml::from_str(&args.file.read_all()?)?;
let output = fuk::fuk(config)?;
let out = std::io::stdout(); let mut out = out.lock(); args.format.render(&output, &mut out)?;
Ok(())}