@@ -4,6 +4,7 @@ use std::process::exit;
4
4
use std:: fs;
5
5
use serde:: { Deserialize , Serialize } ;
6
6
use directories:: BaseDirs ;
7
+ use colored:: * ;
7
8
8
9
#[ derive( Serialize , Deserialize , Clone ) ]
9
10
#[ serde( rename_all = "kebab-case" ) ]
@@ -17,14 +18,14 @@ pub struct Installation {
17
18
pub struct Config {
18
19
pub default_installation : usize ,
19
20
pub working_installation : Option < usize > ,
20
- pub installations : Vec < Installation > ,
21
+ pub installations : Option < Vec < Installation > > ,
21
22
pub default_developer : Option < String > ,
22
23
}
23
24
24
25
static mut CONFIG : Config = Config {
25
26
default_installation : 0 ,
26
27
working_installation : None ,
27
- installations : vec ! ( ) ,
28
+ installations : None ,
28
29
default_developer : None ,
29
30
} ;
30
31
@@ -50,11 +51,17 @@ impl Config {
50
51
let config_json = Config :: data_dir ( ) . join ( "config.json" ) ;
51
52
if !config_json. exists ( ) {
52
53
println ! (
53
- "It seems you don't have Geode installed! \
54
+ "{}{}{}{}" ,
55
+ "WARNING: It seems you don't have Geode installed! \
54
56
Please install Geode first using the official installer \
55
- (https://github.com/geode-sdk/installer/releases/latest)"
57
+ (". yellow( ) ,
58
+ "https://github.com/geode-sdk/installer/releases/latest" . cyan( ) ,
59
+ ")" . yellow( ) ,
60
+ "\n You may still use the CLI, but be warned that certain \
61
+ operations will cause crashes.\n ". purple( )
56
62
) ;
57
- exit ( 1 ) ;
63
+ fs:: create_dir_all ( Config :: data_dir ( ) ) . unwrap ( ) ;
64
+ return ;
58
65
}
59
66
CONFIG = match serde_json:: from_str (
60
67
& fs:: read_to_string ( & config_json) . unwrap ( )
@@ -65,13 +72,18 @@ impl Config {
65
72
exit ( 1 ) ;
66
73
}
67
74
} ;
68
- if CONFIG . installations . len ( ) == 0 {
75
+ if CONFIG . installations . is_none ( ) {
69
76
println ! (
70
- "It seems you don't have any installations of Geode! \
77
+ "{}{}{}{}" ,
78
+ "WARNING: It seems you don't have any installations of Geode! \
71
79
Please install Geode first using the official installer \
72
- (https://github.com/geode-sdk/installer/releases/latest)"
80
+ (". yellow( ) ,
81
+ "https://github.com/geode-sdk/installer/releases/latest" . cyan( ) ,
82
+ ")" . yellow( ) ,
83
+ "\n You may still use the CLI, but be warned that certain \
84
+ operations will cause crashes.\n ". purple( )
73
85
) ;
74
- exit ( 1 ) ;
86
+ return ;
75
87
}
76
88
if CONFIG . working_installation . is_none ( ) {
77
89
CONFIG . working_installation = Some ( CONFIG . default_installation ) ;
@@ -93,6 +105,8 @@ impl Config {
93
105
}
94
106
95
107
pub fn work_inst ( ) -> & ' static Installation {
96
- & Config :: get ( ) . installations [ Config :: get ( ) . working_installation . unwrap ( ) ]
108
+ & Config :: get ( ) . installations . as_ref ( ) . unwrap ( ) [
109
+ Config :: get ( ) . working_installation . unwrap ( )
110
+ ]
97
111
}
98
112
}
0 commit comments