@@ -6,6 +6,7 @@ import rustc::syntax::parse::parser;
6
6
import std:: fs;
7
7
import std:: generic_os;
8
8
import std:: io;
9
+ import std:: json;
9
10
import option;
10
11
import option:: { none, some} ;
11
12
import std:: os;
@@ -206,6 +207,36 @@ fn install_file(c: cargo, wd: str, _path: str) {
206
207
install_source ( c, wd) ;
207
208
}
208
209
210
+ fn install_resolved ( c : cargo , wd : str , key : str ) {
211
+ fs:: remove_dir ( wd) ;
212
+ let u = "https://rust-package-index.appspot.com/pkg/" + key;
213
+ let p = run:: program_output ( "curl" , [ u] ) ;
214
+ if p. status != 0 {
215
+ fail #fmt[ "Fetch of %s failed: %s" , u, p. err ] ;
216
+ }
217
+ let j = json:: from_str ( p. out ) ;
218
+ alt j {
219
+ some ( json:: dict ( _j) ) {
220
+ alt _j. find ( "install" ) {
221
+ some ( json:: string ( g) ) {
222
+ log #fmt[ "Resolved: %s -> %s" , key, g] ;
223
+ cmd_install ( c, [ "cargo" , "install" , g] ) ;
224
+ }
225
+ _ { fail #fmt[ "Bogus install: '%s'" , p. out ] ; }
226
+ }
227
+ }
228
+ _ { fail #fmt[ "Bad json: '%s'" , p. out ] ; }
229
+ }
230
+ }
231
+
232
+ fn install_uuid ( c : cargo , wd : str , uuid : str ) {
233
+ install_resolved ( c, wd, "by-uuid/" + uuid) ;
234
+ }
235
+
236
+ fn install_named ( c : cargo , wd : str , name : str ) {
237
+ install_resolved ( c, wd, "by-name/" + name) ;
238
+ }
239
+
209
240
fn cmd_install ( c : cargo , argv : [ str ] ) {
210
241
// cargo install <pkg>
211
242
if vec:: len ( argv) < 3 u {
@@ -226,6 +257,11 @@ fn cmd_install(c: cargo, argv: [str]) {
226
257
} else if str:: starts_with ( argv[ 2 ] , "file:" ) {
227
258
let path = rest ( argv[ 2 ] , 5 u) ;
228
259
install_file ( c, wd, path) ;
260
+ } else if str:: starts_with ( argv[ 2 ] , "uuid:" ) {
261
+ let uuid = rest ( argv[ 2 ] , 5 u) ;
262
+ install_uuid ( c, wd, uuid) ;
263
+ } else {
264
+ install_named ( c, wd, argv[ 2 ] ) ;
229
265
}
230
266
}
231
267
0 commit comments