Skip to content

Commit

Permalink
feat(cli): added pre-flight shell check
Browse files Browse the repository at this point in the history
Addresses #314.
  • Loading branch information
arctic-hen7 committed Dec 16, 2023
1 parent 3fff7be commit 76a38f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/perseus-cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use thiserror::Error;
/// All errors that can be returned by the CLI.
#[derive(Error, Debug)]
pub enum Error {
#[error("couldn't find your system shell (sh on unix and powershell on windows), which is required to run the perseus cli")]
ShellNotPresent {
#[source]
source: std::io::Error,
},
#[error("couldn't find `cargo`, which is a dependency of this cli (set 'PERSEUS_CARGO_PATH' to another location if you've installed it elsewhere)")]
CargoNotPresent {
#[source]
Expand Down
16 changes: 16 additions & 0 deletions packages/perseus-cli/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ pub fn check_env(global_opts: &Opts) -> Result<(), Error> {
#[cfg(windows)]
let shell_param = "-command";

// Check for the shell before anything else (#314)
let shell_res = Command::new(shell_exec)
.arg("--version")
.output()
.map_err(|err| Error::ShellNotPresent { source: err })?;
let exit_code = match shell_res.status.code() {
Some(exit_code) => exit_code,
None if shell_res.status.success() => 0,
None => 1,
};
if exit_code != 0 {
return Err(Error::ShellNotPresent {
source: std::io::Error::new(std::io::ErrorKind::NotFound, "non-zero exit code"),
});
}

// Check for `cargo`
let cargo_cmd = global_opts.cargo_engine_path.to_string() + " --version";
let cargo_res = Command::new(shell_exec)
Expand Down

0 comments on commit 76a38f3

Please sign in to comment.