Skip to content

Commit

Permalink
Add error message if not in cargo folder
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
Hiram van Paassen authored and hmvp committed Jun 15, 2019
1 parent 91d6e95 commit 846e178
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub enum Error {
NoLibraryTargetFound,
NoMatchingBinaryTargetFound,
NoTargetProvided,
NotACargoFolder,
Syntax(String),
}
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ fn choose_target<'a>(args: &Arguments, manifest: &'a Manifest) -> Result<&'a Tar

fn run(args: &Arguments) -> Result<(), Error> {
let manifest: Manifest = {
let output = process::Command::new("cargo").arg("read-manifest").output();
let stdout = output.map_err(Error::CargoExecutionFailed)?.stdout;
let output = process::Command::new("cargo")
.arg("read-manifest")
.output()
.map_err(Error::CargoExecutionFailed)?;
let stdout = output.stdout;
if !output.status.success() {
return Err(Error::NotACargoFolder);
}
let json_string = String::from_utf8(stdout).expect("Failed reading cargo output");
Manifest::from_str(&json_string)?
};
Expand Down Expand Up @@ -230,6 +236,10 @@ fn main() {
"Error: No matching binary target found.".to_string()
}
Error::NoTargetProvided => "Error: Please specify a target to process.".to_string(),
Error::NotACargoFolder => {
"Error: could not find `Cargo.toml` in `/home/hiram/git` or any parent directory"
.to_string()
}
Error::Syntax(error) => format!("Error: Failed to parse: {}", error),
};
println!("{}", error_string.red());
Expand Down

0 comments on commit 846e178

Please sign in to comment.