11use clap;
2+ use tokio;
23pub mod java_remote;
34pub mod java_ver;
45mod utils;
6+ use console:: Style ;
57use 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