Skip to content

Commit 91249fe

Browse files
committed
Merge pull request #1314 from elly/cargo
Cargo: install-by-name and install-by-uuid
2 parents fd1dd76 + 7953a5d commit 91249fe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/cargo/cargo.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import rustc::syntax::parse::parser;
66
import std::fs;
77
import std::generic_os;
88
import std::io;
9+
import std::json;
910
import option;
1011
import option::{none, some};
1112
import std::os;
@@ -206,6 +207,36 @@ fn install_file(c: cargo, wd: str, _path: str) {
206207
install_source(c, wd);
207208
}
208209

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+
209240
fn cmd_install(c: cargo, argv: [str]) {
210241
// cargo install <pkg>
211242
if vec::len(argv) < 3u {
@@ -226,6 +257,11 @@ fn cmd_install(c: cargo, argv: [str]) {
226257
} else if str::starts_with(argv[2], "file:") {
227258
let path = rest(argv[2], 5u);
228259
install_file(c, wd, path);
260+
} else if str::starts_with(argv[2], "uuid:") {
261+
let uuid = rest(argv[2], 5u);
262+
install_uuid(c, wd, uuid);
263+
} else {
264+
install_named(c, wd, argv[2]);
229265
}
230266
}
231267

0 commit comments

Comments
 (0)