Skip to content

Commit

Permalink
fix: run command hanging if no command was supplied; don't allow inte…
Browse files Browse the repository at this point in the history
…ractive stdin
  • Loading branch information
tangowithfoxtrot committed Mar 1, 2024
1 parent 553a1be commit ef48b84
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
23 changes: 22 additions & 1 deletion 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 @@ -13,6 +13,7 @@ Bitwarden Secrets Manager CLI
keywords = ["bitwarden", "secrets-manager", "cli"]

[dependencies]
atty = "0.2.14"
bat = { version = "0.24.0", features = [
"regex-onig",
], default-features = false }
Expand Down
20 changes: 20 additions & 0 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use atty::Stream;
use std::{io::Read, path::PathBuf, process, str::FromStr};

use bitwarden::{
Expand Down Expand Up @@ -638,6 +639,25 @@ async fn process_commands() -> Result<()> {
no_inherit_env,
project_id,
} => {
let user_command = if command.is_empty() {
if atty::is(Stream::Stdin) {
eprintln!("{}", Cli::command().render_help().ansi());
std::process::exit(1);
}

let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
buffer
} else {
command.join(" ")
};

if user_command.is_empty() {
let mut cmd = Cli::command();
eprintln!("{}", cmd.render_help().ansi());
std::process::exit(1);
}

let res = if let Some(project_id) = project_id {
client
.secrets()
Expand Down

0 comments on commit ef48b84

Please sign in to comment.