Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
add -u flag for subcommands:use,install,list-remote
Browse files Browse the repository at this point in the history
  • Loading branch information
CNCSMonster committed Sep 21, 2024
1 parent 5b0ab2d commit 274b82e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fgm"
authors = ["cncsmonster <[email protected]>"]
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Fast and simple go version manager"
Expand Down
22 changes: 18 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub enum Subcommand {
/// Install a specific version of Go
Install {
version: String,
#[clap(short, long)]
update: bool,
},
/// List installed versions
#[clap(name = "list",visible_aliases = &["ls"])]
Expand All @@ -40,6 +42,9 @@ pub enum Subcommand {
// reverse
#[clap(short, long)]
reverse: bool,
// update cache
#[clap(short, long)]
update: bool,
},
/// Uninstall a specific version of Go
Uninstall {
Expand All @@ -48,6 +53,8 @@ pub enum Subcommand {
/// Use a specific version of Go
Use {
version: String,
#[clap(short, long)]
update: bool,
},
/// Print and set up required environment variables for fgm
///
Expand Down Expand Up @@ -83,21 +90,28 @@ pub enum Subcommand {
}

impl Subcommand {
pub fn run(&self, ctx: &FgmContext) -> Result<()> {
pub fn run(&self, ctx: &mut FgmContext) -> Result<()> {
match self {
Subcommand::Install { version } => {
Subcommand::Install { version, update } => {
ctx.update = *update;
install(ctx, version)?;
}
Subcommand::LsLocal { sort, reverse } => {
list_installed(ctx, *sort, *reverse);
}
Subcommand::LsRemote { sort, reverse } => {
Subcommand::LsRemote {
sort,
reverse,
update,
} => {
ctx.update = *update;
list_remote(ctx, *sort, *reverse)?;
}
Subcommand::Uninstall { version } => {
uninstall(ctx, version)?;
}
Subcommand::Use { version } => {
Subcommand::Use { version, update } => {
ctx.update = *update;
_use(ctx, version)?;
}
Subcommand::Init => println!("{}", init_script(ctx)),
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ fn init_context() -> FgmContext {
}

fn main() {
let ctx = init_context();
let mut ctx = init_context();
let cli = cli::Cli::parse();
if let Err(e) = cli.sub.run(&ctx) {
if let Err(e) = cli.sub.run(&mut ctx) {
println!("{:?}", e);
}
}

0 comments on commit 274b82e

Please sign in to comment.