Skip to content

Commit d456a75

Browse files
committed
feat(add i686 support, add 'disable' command): add i686 support, add 'disable' command
1 parent d94ebb5 commit d456a75

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

src/java_remote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub async fn get_remote(version: &str) {
4343
if !version_list.contains(&version_name) {
4444
// println!("{}", file_name);
4545
let download_url = format!(
46-
"https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/{}/jdk/x64/windows/{}",
47-
version, file_name
46+
"https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/{}/jdk/{}/windows/{}",
47+
version, arch, file_name
4848
);
4949

5050
// println!("{}", download_url);

src/java_ver.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ pub fn version_record(file: &Path, java_config: Java) {
8282
}
8383

8484
pub fn enable_version(version: &str) {
85-
let contents = std::fs::read_to_string("./versions.toml").expect("Unable to load");
85+
let mut current_location = std::env::current_exe().unwrap();
86+
current_location.pop();
87+
current_location.push("versions.toml");
88+
let contents = std::fs::read_to_string(&current_location).expect("Unable to load Version Files");
8689
let store: Store = toml::from_str(&contents).unwrap();
8790
if let Some(list) = store.Java_Version {
8891
for element in list {

src/main.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use clap;
2+
use tokio;
23
pub mod java_remote;
34
pub mod java_ver;
45
mod utils;
6+
use console::Style;
57
use dotenv::dotenv;
68

79
#[tokio::main]
@@ -10,27 +12,32 @@ async fn main() {
1012
let matches = clap::App::new("java-version")
1113
.about("Manage Java Developer Kit Versions")
1214
.author("ZuoXichen")
13-
.version("0.1.1")
15+
.version("0.1.2")
1416
.subcommand(
1517
clap::App::new("list")
1618
.about("List local available JDKs")
1719
.short_flag('l')
1820
.subcommand(
1921
clap::App::new("remote").about("List available JDKs from remote server"),
2022
)
21-
.subcommand(clap::App::new("local").about("List local jdk versions"))
23+
.subcommand(clap::App::new("local").about("List local jdk versions")),
2224
)
2325
.subcommand(
2426
clap::App::new("enable")
2527
.about("enable one jdk version globally")
2628
.arg(clap::Arg::new("version").takes_value(true)),
2729
)
30+
.subcommand(
31+
clap::App::new("disable")
32+
.about("disable jdk version globally")
33+
.arg(clap::Arg::new("version").takes_value(true)),
34+
)
2835
.subcommand(
2936
clap::App::new("get").subcommand(
3037
clap::App::new("remote").arg(
3138
clap::Arg::new("version")
3239
.takes_value(true)
33-
.value_name("Version")
40+
.value_name("Version"),
3441
),
3542
),
3643
)
@@ -43,26 +50,36 @@ async fn main() {
4350
} else if let Some(_) = f.subcommand_matches("local") {
4451
let version_list = java_ver::read_version();
4552
println!("All available JDKs:");
46-
for element in version_list
47-
{
53+
for element in version_list {
4854
println!("{}", element);
4955
}
5056
}
51-
}else if let Some(g) = matches.subcommand_matches("get"){
57+
} else if let Some(g) = matches.subcommand_matches("get") {
5258
if let Some(r) = g.subcommand_matches("remote") {
53-
if let Some(v) = r.value_of("version")
54-
{
59+
if let Some(v) = r.value_of("version") {
5560
let version = String::from(v);
56-
let _:i32 = version.trim().parse().expect("Please enter a number");
61+
let _: i32 = version.trim().parse().expect("Please enter a number");
5762
java_remote::get_remote(v).await;
5863
}
59-
6064
}
61-
} else if let Some(e) = matches.subcommand_matches("enable"){
62-
if let Some(version) = matches.value_of("version")
63-
{
65+
} else if let Some(e) = matches.subcommand_matches("enable") {
66+
if let Some(version) = matches.value_of("version") {
6467
java_ver::enable_version(version);
6568
}
66-
69+
} else if let Some(_) = matches.subcommand_matches("disable") {
70+
let mut current_location = std::env::current_exe().unwrap();
71+
current_location.pop();
72+
current_location.push("OpenJDK/");
73+
let result = std::fs::remove_dir_all(&current_location);
74+
match result {
75+
Ok(_) => {
76+
let green = Style::new().green();
77+
println!("{}", green.apply_to("Disable JDK SUCCESS"))
78+
}
79+
Err(e) => {
80+
let red = Style::new().red();
81+
println!("{} {}", red.apply_to("Disable JDK FAILED"), e.to_string());
82+
}
83+
}
6784
}
6885
}

0 commit comments

Comments
 (0)