1use crate::{commands, config::Config};
3use clap::{Parser, Subcommand};
4
5#[derive(Parser, Debug)]
7#[command(author, version, about = "A high-performance Go version management tool")]
8pub struct Cli {
9 #[arg(short, long, global = true)]
11 pub verbose: bool,
12
13 #[arg(short, long, global = true)]
15 pub quiet: bool,
16
17 #[command(subcommand)]
18 pub command: Commands,
19}
20
21#[derive(Subcommand, Debug)]
22pub enum Commands {
23 Install {
25 version: String,
27 #[arg(short, long)]
29 force: bool,
30 },
31 Use {
33 version: String,
35 #[arg(short, long)]
37 global: bool,
38 },
39 Uninstall {
41 version: String,
43 },
44 List {
46 #[arg(short, long)]
48 all: bool,
49 },
50 Status,
52 Info {
54 version: String,
56 },
57}
58
59impl Cli {
60 pub async fn run(&self) -> anyhow::Result<()> {
61 let config = Config::new()?;
62
63 match &self.command {
64 Commands::Install { version, force } => {
65 commands::install(version, &config, *force).await
66 }
67 Commands::Use { version, global } => commands::switch(version, &config, *global, false),
68 Commands::Uninstall { version } => commands::uninstall(version, &config),
69 Commands::List { all } => commands::list(&config, *all),
70 Commands::Status => commands::status(&config),
71 Commands::Info { version } => commands::info(version, &config),
72 }
73 }
74}