gitswitch 0.1.0

Switch between GitHub accounts (git identity + gh auth) on the fly
mod cli;
mod commands;
mod config;
mod gh;
mod git;

use anyhow::Result;
use clap::Parser;

use cli::{Cli, Command};
use config::Config;

fn main() {
    if let Err(e) = run() {
        eprintln!("error: {e:#}");
        std::process::exit(1);
    }
}

fn run() -> Result<()> {
    let args = Cli::parse();
    let config_path = Config::default_path()?;

    match args.command {
        Command::Add { alias } => commands::add(&config_path, &alias),
        Command::List => commands::list(&config_path),
        Command::Current => commands::current(&config_path),
        Command::Remove { alias } => commands::remove(&config_path, &alias),
        Command::Switch(args) => {
            let alias = cli::resolve_switch_alias(&args).map_err(anyhow::Error::msg)?;
            commands::switch(&config_path, alias)
        }
    }
}