Skip to content

Commit

Permalink
fix: panic on invalid shell
Browse files Browse the repository at this point in the history
  • Loading branch information
tangowithfoxtrot committed Mar 18, 2024
1 parent 5fc71d3 commit 6ad88b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/bws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ toml = "0.8.10"
uuid = { version = "^1.7.0", features = ["serde"] }

bitwarden = { workspace = true, features = ["secrets"] }
which = "6.0.0"

[dev-dependencies]
tempfile = "3.10.0"
22 changes: 14 additions & 8 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod state;
use config::ProfileKey;
use render::{serialize_response, Color, Output};
use uuid::Uuid;
use which::which;

#[derive(Parser, Debug)]
#[command(name = "bws", version, about = "Bitwarden Secrets CLI", long_about = None)]
Expand Down Expand Up @@ -639,6 +640,19 @@ async fn process_commands() -> Result<()> {
no_inherit_env,
project_id,

Check warning on line 641 in crates/bws/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bws/src/main.rs#L638-L641

Added lines #L638 - L641 were not covered by tests
} => {
let shell = match std::env::consts::OS {
os if os == "linux" || os == "macos" || os.contains("bsd") => {
shell.unwrap_or_else(|| "sh".to_string())

Check warning on line 645 in crates/bws/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bws/src/main.rs#L643-L645

Added lines #L643 - L645 were not covered by tests
}
"windows" => shell.unwrap_or_else(|| "powershell".to_string()),
_ => unreachable!(),

Check warning on line 648 in crates/bws/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bws/src/main.rs#L647-L648

Added lines #L647 - L648 were not covered by tests
};

if !which(&shell).is_ok() {
eprintln!("Error: shell '{}' not found", shell);
std::process::exit(1);
}

Check warning on line 654 in crates/bws/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bws/src/main.rs#L651-L654

Added lines #L651 - L654 were not covered by tests

let user_command = if command.is_empty() {
if atty::is(Stream::Stdin) {
eprintln!("{}", Cli::command().render_help().ansi());
Expand Down Expand Up @@ -693,14 +707,6 @@ async fn process_commands() -> Result<()> {
}

Check warning on line 707 in crates/bws/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bws/src/main.rs#L701-L707

Added lines #L701 - L707 were not covered by tests
}

let shell = match std::env::consts::OS {
os if os == "linux" || os == "macos" || os.contains("bsd") => {
shell.unwrap_or_else(|| "sh".to_string())
}
"windows" => shell.unwrap_or_else(|| "powershell".to_string()),
_ => unreachable!(),
};

let mut command = process::Command::new(shell);
command
.arg("-c")
Expand Down

0 comments on commit 6ad88b8

Please sign in to comment.