mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
Merge pull request #311 from ouch-org/check-eof-when-asking-question
Check for EOF when asking questions
This commit is contained in:
commit
d1477e2368
@ -58,6 +58,7 @@ Categories Used:
|
||||
- Fix incorrect warnings for decompression [\#270](https://github.com/ouch-org/ouch/pull/270) ([figsoda](https://github.com/figsoda))
|
||||
- Fix infinite compression if output file is inside the input folder [\#288](https://github.com/ouch-org/ouch/pull/288) ([figsoda](https://github.com/figsoda))
|
||||
- Fix not overwriting a folder when compressing [\#295](https://github.com/ouch-org/ouch/pull/295) ([marcospb19](https://github.com/marcospb19))
|
||||
- Check for EOF when asking questions [\#311](https://github.com/ouch-org/ouch/pull/311) ([marcospb19](https://github.com/marcospb19))
|
||||
|
||||
### Improvements
|
||||
|
||||
|
@ -14,7 +14,7 @@ use fs_err as fs;
|
||||
use super::{strip_cur_dir, to_utf};
|
||||
use crate::{
|
||||
accessible::is_running_in_accessible_mode,
|
||||
error::{Error, Result},
|
||||
error::{Error, FinalError, Result},
|
||||
utils::{self, colors},
|
||||
};
|
||||
|
||||
@ -145,7 +145,17 @@ impl<'a> Confirmation<'a> {
|
||||
io::stdout().flush()?;
|
||||
|
||||
let mut answer = String::new();
|
||||
io::stdin().read_line(&mut answer)?;
|
||||
let bytes_read = io::stdin().read_line(&mut answer)?;
|
||||
|
||||
if bytes_read == 0 {
|
||||
let error = FinalError::with_title("Unexpected EOF when asking question.")
|
||||
.detail("When asking the user:")
|
||||
.detail(format!(" \"{message}\""))
|
||||
.detail("Expected 'y' or 'n' as answer, but found EOF instead.")
|
||||
.hint("If using Ouch in scripting, consider using `--yes` and `--no`.");
|
||||
|
||||
return Err(error.into());
|
||||
}
|
||||
|
||||
answer.make_ascii_lowercase();
|
||||
match answer.trim() {
|
||||
|
@ -9,6 +9,7 @@ macro_rules! ouch {
|
||||
($($e:expr),*) => {
|
||||
$crate::utils::cargo_bin()
|
||||
$(.arg($e))*
|
||||
.arg("--yes")
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user