dialtone 0.1.0

Dialtone Command Line Client
pub(crate) mod commands;
pub(crate) mod row_obj;

use clap::{arg, Arg, ArgAction, Command};
use commands::{login::do_login, logout::do_logout, site_info::do_site_info};
use dialtone_ccli_util::config::{dirs::init, DialtoneConfig};
use dialtone_common::utils::version::DT_VERSION;
use simplelog::*;

#[allow(unused_variables)]
#[tokio::main]
async fn main() {
    init(&[]).unwrap();
    TermLogger::init(
        LevelFilter::Info,
        Config::default(),
        TerminalMode::Stderr,
        ColorChoice::Auto,
    )
    .unwrap();
    let config = DialtoneConfig::from_config_dir();

    let matches = Command::new("dialtone")
        .about("Dialtone command line client.")
        .version(DT_VERSION)
        .propagate_version(true)
        .subcommand_required(true)
        .arg_required_else_help(true)
        .subcommand(
            Command::new("site-info")
                .about("Get site information")
                .arg(
                    Arg::new("JSON_OUTPUT")
                        .short('J')
                        .long("json")
                        .action(ArgAction::SetTrue),
                )
                .arg(arg!([HOST_NAME])),
        )
        .subcommand(
            Command::new("login")
                .about("Login to a site")
                .arg(arg!([ACCOUNT])),
        )
        .subcommand(
            Command::new("logout")
                .about("Logout of a site")
                .arg(arg!([ACCOUNT])),
        )
        .get_matches();

    match matches.subcommand() {
        Some(("site-info", sub_matches)) => {
            let host_name = sub_matches.get_one::<String>("HOST_NAME");
            let json_output = sub_matches.get_one::<bool>("JSON_OUTPUT").unwrap();
            do_site_info(host_name, json_output).await
        }
        Some(("login", sub_matches)) => do_login(sub_matches.get_one::<String>("ACCOUNT").unwrap()),
        Some(("logout", sub_matches)) => {
            do_logout(sub_matches.get_one::<String>("ACCOUNT").unwrap())
        }
        _ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
    }
}