Skip to main content

tidepool_gvm/
cli.rs

1//! Command line interface definition
2use crate::{commands, config::Config};
3use clap::{Parser, Subcommand};
4
5/// Tidepool GVM - A high-performance Go Version Manager
6#[derive(Parser, Debug)]
7#[command(author, version, about = "A high-performance Go version management tool")]
8pub struct Cli {
9    /// Verbose mode
10    #[arg(short, long, global = true)]
11    pub verbose: bool,
12
13    /// Quiet mode (only output errors)
14    #[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 a specific Go version
24    Install {
25        /// The Go version to install (e.g., 1.21.3)
26        version: String,
27        /// Force re-installation
28        #[arg(short, long)]
29        force: bool,
30    },
31    /// Switch to a specific Go version
32    Use {
33        /// The Go version to use (e.g., 1.21.3)
34        version: String,
35        /// Set as global version
36        #[arg(short, long)]
37        global: bool,
38    },
39    /// Uninstall a specific Go version
40    Uninstall {
41        /// The Go version to uninstall (e.g., 1.21.3)
42        version: String,
43    },
44    /// List Go versions
45    List {
46        /// List all available remote versions
47        #[arg(short, long)]
48        all: bool,
49    },
50    /// Show the current Go version status
51    Status,
52    /// Show detailed information about a Go version
53    Info {
54        /// The Go version to show information for (e.g., 1.21.3)
55        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}