use anyhow::Result;
use clap::Parser;
use crate::{_use, config::FgmConfig, env, install, list_installed, list_remote, uninstall};
#[derive(Parser, Debug)]
pub struct Cli {
#[clap(subcommand)]
pub sub: Subcommand,
}
#[derive(Parser, Debug, Clone)]
pub enum Subcommand {
Install { version: String },
List {
#[clap(short, long)]
sort: bool,
},
#[clap(name = "list-remote")]
LsRemote {
#[clap(short, long)]
sort: bool,
},
Uninstall { version: String },
Use { version: String },
Env,
}
impl Subcommand {
pub fn run(&self, config: &FgmConfig) -> Result<()> {
match self {
Subcommand::Install { version } => {
install(config, version)?;
}
Subcommand::List { sort } => {
list_installed(config, *sort);
}
Subcommand::LsRemote { sort } => {
list_remote(config, *sort)?;
}
Subcommand::Uninstall { version } => {
uninstall(config, version)?;
}
Subcommand::Use { version } => {
_use(config, version)?;
}
Subcommand::Env => println!("{}", env(config)),
}
Ok(())
}
}