use std::process::exit;
use crate::cli::{Cli, Commands};
use anyhow::Result;
use clap::Parser;
use command::*;
use simple_logger::SimpleLogger;
mod cli;
mod command;
fn main() {
match run() {
Err(why) => {
log::error!("{why}");
exit(1);
}
Ok(_) => exit(0),
}
}
fn run() -> Result<()> {
let cli = Cli::parse();
SimpleLogger::new()
.with_level(cli.verbose.log_level_filter())
.env()
.init()?;
if cli.mirror {
melatonin::set_mirror(true);
}
match cli.command {
Commands::Fetch { beta } => fetch::fetch(beta),
Commands::Install { version } => install::install(version),
Commands::List => list::list(),
Commands::Pin {
global,
version,
directory,
} => pin::pin(global, version, directory),
Commands::Setup {} => setup::setup(),
Commands::Uninstall { version } => uninstall::uninstall(version),
Commands::Prefix { version } => prefix::prefix(version),
}
}