@@ -76,17 +76,7 @@ fn parse_version(str: &str) -> Result<Version, semver::Error> {
76
76
}
77
77
78
78
fn uninstall ( config : & mut Config ) -> bool {
79
- let sdk_path: & Path = if let Some ( p) = & config. sdk_path {
80
- if !p. exists ( ) {
81
- fail ! ( "SDK path \" {}\" does not exist" , p. display( ) ) ;
82
- return false ;
83
- }
84
-
85
- p
86
- } else {
87
- fail ! ( "Unable to uninstall SDK as it is not installed" ) ;
88
- return false ;
89
- } ;
79
+ let sdk_path = Config :: sdk_path ( ) ;
90
80
91
81
warn ! ( "Are you sure you want to uninstall SDK?" ) ;
92
82
print ! ( " (type 'Yes' to proceed) " ) ;
@@ -106,7 +96,6 @@ fn uninstall(config: &mut Config) -> bool {
106
96
return false ;
107
97
}
108
98
109
- config. sdk_path = None ;
110
99
done ! ( "Uninstalled Geode SDK" ) ;
111
100
return true ;
112
101
}
@@ -115,7 +104,7 @@ fn install(config: &mut Config, path: PathBuf) {
115
104
116
105
let parent = path. parent ( ) . unwrap ( ) ;
117
106
118
- if config . sdk_path . is_some ( ) {
107
+ if std :: env :: var ( "GEODE_SDK" ) . is_ok ( ) {
119
108
fail ! ( "SDK is already installed" ) ;
120
109
info ! ( "Use --reinstall if you want to remove the existing installation" ) ;
121
110
} else if !parent. exists ( ) {
@@ -140,7 +129,9 @@ fn install(config: &mut Config, path: PathBuf) {
140
129
let repo = builder. clone ( "https://github.com/geode-sdk/geode" , & path)
141
130
. nice_unwrap ( "Could not download SDK" ) ;
142
131
143
- config. sdk_path = Some ( path) ;
132
+ // TODO: set GEODE_SDK enviroment var
133
+
134
+ info ! ( "Please set the GEODE_SDK enviroment variable to {}" , path. to_str( ) . unwrap( ) ) ;
144
135
145
136
switch_to_tag ( config, & repo) ;
146
137
@@ -167,7 +158,7 @@ fn update(config: &mut Config, branch: Option<Branch>) {
167
158
168
159
// Initialize repository
169
160
let repo = Repository :: open (
170
- config . sdk_path . as_ref ( ) . nice_unwrap ( "Unable to update SDK as it is not installed" )
161
+ Config :: sdk_path ( )
171
162
) . nice_unwrap ( "Could not initialize local SDK repository" ) ;
172
163
173
164
// Fetch
@@ -200,7 +191,7 @@ fn update(config: &mut Config, branch: Option<Branch>) {
200
191
} else if !merge_analysis. is_fast_forward ( ) {
201
192
fail ! ( "Cannot update SDK, it has local changes" ) ;
202
193
info ! ( "Go into the repository at {} and manually run `git pull`" ,
203
- config . sdk_path. as_ref ( ) . unwrap ( ) . to_str( ) . unwrap( )
194
+ Config :: sdk_path( ) . to_str( ) . unwrap( )
204
195
) ;
205
196
} else {
206
197
// Change head and checkout
@@ -252,22 +243,18 @@ fn switch_to_tag(config: &mut Config, repo: &Repository) {
252
243
}
253
244
254
245
fn install_binaries ( config : & mut Config ) {
255
- config. sdk_path . as_ref ( ) . nice_unwrap (
256
- "SDK not installed! Use `geode sdk install` to install \
257
- Geode or `geode config setup` to set up the CLI."
258
- ) ;
259
246
update ( config, None ) ;
260
247
let release_tag: String ;
261
248
let target_dir: PathBuf ;
262
249
if config. sdk_nightly {
263
250
info ! ( "Installing nightly binaries" ) ;
264
251
release_tag = "Nightly" . into ( ) ;
265
- target_dir = config . sdk_path . as_ref ( ) . unwrap ( ) . join ( "bin/nightly" ) ;
252
+ target_dir = Config :: sdk_path ( ) . join ( "bin/nightly" ) ;
266
253
} else {
267
- let ver = get_version ( config ) ;
254
+ let ver = get_version ( ) ;
268
255
info ! ( "Installing binaries for {}" , ver) ;
269
256
release_tag = format ! ( "v{}" , ver) ;
270
- target_dir = config . sdk_path . as_ref ( ) . unwrap ( ) . join ( format ! ( "bin/{}" , ver) ) ;
257
+ target_dir = Config :: sdk_path ( ) . join ( format ! ( "bin/{}" , ver) ) ;
271
258
}
272
259
let url = format ! ( "https://api.github.com/repos/geode-sdk/geode/releases/tags/{}" , release_tag) ;
273
260
@@ -317,10 +304,10 @@ fn install_binaries(config: &mut Config) {
317
304
done ! ( "Binaries installed" ) ;
318
305
}
319
306
320
- pub fn get_version ( config : & mut Config ) -> Version {
307
+ pub fn get_version ( ) -> Version {
321
308
Version :: parse (
322
309
fs:: read_to_string (
323
- config . sdk_path . as_ref ( ) . nice_unwrap ( "SDK not installed!" ) . join ( "VERSION" )
310
+ Config :: sdk_path ( ) . join ( "VERSION" )
324
311
) . nice_unwrap ( "Unable to read SDK version, make sure you are using SDK v0.4.2 or later" ) . as_str ( )
325
312
) . nice_unwrap ( "Invalid SDK version" )
326
313
}
@@ -346,7 +333,7 @@ pub fn subcommand(config: &mut Config, cmd: Sdk) {
346
333
} ,
347
334
Sdk :: Uninstall => { uninstall ( config) ; } ,
348
335
Sdk :: Update { branch } => update ( config, branch) ,
349
- Sdk :: Version => info ! ( "Geode SDK version: {}" , get_version( config ) ) ,
336
+ Sdk :: Version => info ! ( "Geode SDK version: {}" , get_version( ) ) ,
350
337
Sdk :: InstallBinaries => install_binaries ( config) ,
351
338
}
352
339
}
0 commit comments