Skip to content

Commit

Permalink
suggest sync/init to user as appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Bowland committed Jan 24, 2012
1 parent 2898dcc commit fe70212
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/cargo/cargo.rs
Expand Up @@ -476,6 +476,25 @@ fn install_package(c: cargo, wd: str, pkg: package) {
}
}

fn cargo_suggestion(c: cargo, syncing: bool, fallback: fn())
{
if c.sources.size() == 0u {
error("No sources defined. You may wish to run " +
"\"cargo init\" then \"cargo sync\".");
ret;
}
if !syncing {
let npkg = 0u;
c.sources.values({ |v| npkg += vec::len(v.packages) });
if npkg == 0u {
error("No packages known. You may wish to run " +
"\"cargo sync\".");
ret;
}
}
fallback();
}

fn install_uuid(c: cargo, wd: str, uuid: str) {
let ps = [];
for_each_package(c, { |s, p|
Expand All @@ -489,7 +508,7 @@ fn install_uuid(c: cargo, wd: str, uuid: str) {
install_package(c, wd, p);
ret;
} else if vec::len(ps) == 0u {
error("No packages.");
cargo_suggestion(c, false, { || error("No packages match uuid."); });
ret;
}
error("Found multiple packages:");
Expand All @@ -510,7 +529,7 @@ fn install_named(c: cargo, wd: str, name: str) {
install_package(c, wd, p);
ret;
} else if vec::len(ps) == 0u {
error("No packages.");
cargo_suggestion(c, false, { || error("No packages match name."); });
ret;
}
error("Found multiple packages:");
Expand Down Expand Up @@ -651,6 +670,7 @@ fn cmd_sync(c: cargo, argv: [str]) {
if vec::len(argv) == 3u {
sync_one(c, argv[2], c.sources.get(argv[2]));
} else {
cargo_suggestion(c, true, { || } );
c.sources.items { |k, v|
sync_one(c, k, v);
}
Expand Down

0 comments on commit fe70212

Please sign in to comment.