diff options
| author | Brian Anderson <andersrb@gmail.com> | 2011-12-15 18:26:11 -0800 |
|---|---|---|
| committer | Brian Anderson <andersrb@gmail.com> | 2011-12-15 18:26:11 -0800 |
| commit | 91249fed82e572df1eefea1db26b42895044ba4b (patch) | |
| tree | 8c579955a062acd6983ee8cfbc6506a0d23a929e | |
| parent | fd1dd76977f808ec40796d6ca66e4bf98de6de9c (diff) | |
| parent | 7953a5dcfcb779a4a127b34e9cc85b0359c45d1a (diff) | |
Merge pull request #1314 from elly/cargo
Cargo: install-by-name and install-by-uuid
| -rw-r--r-- | src/cargo/cargo.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs index 49a5367860e..757fa31d4e0 100644 --- a/src/cargo/cargo.rs +++ b/src/cargo/cargo.rs @@ -6,6 +6,7 @@ import rustc::syntax::parse::parser; import std::fs; import std::generic_os; import std::io; +import std::json; import option; import option::{none, some}; import std::os; @@ -206,6 +207,36 @@ fn install_file(c: cargo, wd: str, _path: str) { install_source(c, wd); } +fn install_resolved(c: cargo, wd: str, key: str) { + fs::remove_dir(wd); + let u = "https://rust-package-index.appspot.com/pkg/" + key; + let p = run::program_output("curl", [u]); + if p.status != 0 { + fail #fmt["Fetch of %s failed: %s", u, p.err]; + } + let j = json::from_str(p.out); + alt j { + some (json::dict(_j)) { + alt _j.find("install") { + some (json::string(g)) { + log #fmt["Resolved: %s -> %s", key, g]; + cmd_install(c, ["cargo", "install", g]); + } + _ { fail #fmt["Bogus install: '%s'", p.out]; } + } + } + _ { fail #fmt["Bad json: '%s'", p.out]; } + } +} + +fn install_uuid(c: cargo, wd: str, uuid: str) { + install_resolved(c, wd, "by-uuid/" + uuid); +} + +fn install_named(c: cargo, wd: str, name: str) { + install_resolved(c, wd, "by-name/" + name); +} + fn cmd_install(c: cargo, argv: [str]) { // cargo install <pkg> if vec::len(argv) < 3u { @@ -226,6 +257,11 @@ fn cmd_install(c: cargo, argv: [str]) { } else if str::starts_with(argv[2], "file:") { let path = rest(argv[2], 5u); install_file(c, wd, path); + } else if str::starts_with(argv[2], "uuid:") { + let uuid = rest(argv[2], 5u); + install_uuid(c, wd, uuid); + } else { + install_named(c, wd, argv[2]); } } |
