dwh 0.7.1

A library to use the digitronic protocol dwh
Documentation
use std::process;

use clap::{command, Parser, ValueEnum};
use dwh::args::{ConnectionArgs, Timeout};

#[derive(Debug, Clone, ValueEnum)]
pub enum Output {
    Text,
    Json,
}

impl Default for Output {
    fn default() -> Self {
        Self::Text
    }
}

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]

pub struct Args {
    pub host: String,

    #[command(flatten)]
    pub connection_args: ConnectionArgs,
    #[command(flatten)]
    pub timeout: Timeout,

    #[arg(short, long)]
    pub output: Option<Output>,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    ctrlc::set_handler(|| {
        process::exit(1);
    })
    .ok();
    let args = Args::parse();
    let mut dwh = dwh::new(args.host)?;
    let hooks = args.connection_args.into_hooks().await?;
    dwh.set_hooks(hooks);
    args.timeout.apply(&mut dwh);

    let credentials = dwh.use_backdoor().await?;

    match args.output.unwrap_or_default() {
        Output::Text => {
            println!("user: {}", credentials.username);
            println!("password: {}", credentials.password);
        }
        Output::Json => {
            println!("{}", serde_json::to_string(&credentials)?);
        }
    };
    Ok(())
}