1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use anyhow::Result;
use clap::Parser;
use crate::{
_use, config::FgmContext, current_version, init_script, install, list_installed, list_remote,
uninstall, update,
};
#[derive(Parser, Debug)]
pub struct Cli {
#[clap(subcommand)]
pub sub: Subcommand,
}
#[derive(Parser, Debug, Clone)]
pub enum Subcommand {
/// Install a specific version of Go
Install {
version: String,
},
/// List installed versions
List {
// sort
#[clap(short, long)]
sort: bool,
},
/// List all remote versions
#[clap(name = "list-remote")]
LsRemote {
// sort
#[clap(short, long)]
sort: bool,
},
/// Uninstall a specific version of Go
Uninstall {
version: String,
},
/// Use a specific version of Go
Use {
version: String,
},
/// Print and set up required environment variables for fgm
///
/// This command generates a series of shell commands that
/// should be evaluated by your shell to create a fgm-ready environment.
///
/// Each shell has its own syntax of evaluating a dynamic expression.
/// For example, evaluating fgm on Bash and Zsh would look like `eval "$(fgm init)"`.
///
/// Now, only Bash and Zsh are supported.It may also work on other shells that support the `export` command.
Init,
Current,
/// show the runtime configuration
Config,
/// Update the fgm remotes index
Update,
}
impl Subcommand {
pub fn run(&self, ctx: &FgmContext) -> Result<()> {
match self {
Subcommand::Install { version } => {
install(ctx, version)?;
}
Subcommand::List { sort } => {
list_installed(ctx, *sort);
}
Subcommand::LsRemote { sort } => {
list_remote(ctx, *sort)?;
}
Subcommand::Uninstall { version } => {
uninstall(ctx, version)?;
}
Subcommand::Use { version } => {
_use(ctx, version)?;
}
Subcommand::Init => println!("{}", init_script(ctx)),
Subcommand::Current => println!(
"{}",
current_version(ctx).unwrap_or("not version selected".to_owned())
),
Subcommand::Config => {
println!("installations_dir: {}", ctx.installations_dir);
println!("gate_path: {}", ctx.gate_path);
println!("remote_source: {}", ctx.remote_source);
}
Subcommand::Update => {
update(ctx)?;
}
}
Ok(())
}
}