Skip to content

Commit bd17319

Browse files
committed
Merge pull request #1637 from grahame/cargo-errors
suggest sync/init to user as appropriate
2 parents 7356126 + fe70212 commit bd17319

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/cargo/cargo.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,25 @@ fn install_package(c: cargo, wd: str, pkg: package) {
476476
}
477477
}
478478

479+
fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
480+
{
481+
if c.sources.size() == 0u {
482+
error("No sources defined. You may wish to run " +
483+
"\"cargo init\" then \"cargo sync\".");
484+
ret;
485+
}
486+
if !syncing {
487+
let npkg = 0u;
488+
c.sources.values({ |v| npkg += vec::len(v.packages) });
489+
if npkg == 0u {
490+
error("No packages known. You may wish to run " +
491+
"\"cargo sync\".");
492+
ret;
493+
}
494+
}
495+
fallback();
496+
}
497+
479498
fn install_uuid(c: cargo, wd: str, uuid: str) {
480499
let ps = [];
481500
for_each_package(c, { |s, p|
@@ -489,7 +508,7 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
489508
install_package(c, wd, p);
490509
ret;
491510
} else if vec::len(ps) == 0u {
492-
error("No packages.");
511+
cargo_suggestion(c, false, { || error("No packages match uuid."); });
493512
ret;
494513
}
495514
error("Found multiple packages:");
@@ -510,7 +529,7 @@ fn install_named(c: cargo, wd: str, name: str) {
510529
install_package(c, wd, p);
511530
ret;
512531
} else if vec::len(ps) == 0u {
513-
error("No packages.");
532+
cargo_suggestion(c, false, { || error("No packages match name."); });
514533
ret;
515534
}
516535
error("Found multiple packages:");
@@ -651,6 +670,7 @@ fn cmd_sync(c: cargo, argv: [str]) {
651670
if vec::len(argv) == 3u {
652671
sync_one(c, argv[2], c.sources.get(argv[2]));
653672
} else {
673+
cargo_suggestion(c, true, { || } );
654674
c.sources.items { |k, v|
655675
sync_one(c, k, v);
656676
}

0 commit comments

Comments
 (0)