diff --git a/Cargo.toml b/Cargo.toml index 4192a77..a9f3ba8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ test-strategy = "0.4.0" default = ["use_zlib", "use_zstd_thin", "unrar"] use_zlib = ["flate2/zlib", "gzp/deflate_zlib", "zip/deflate-zlib"] use_zstd_thin = ["zstd/thin"] +allow_piped_choice = [] # For generating binaries for releases [profile.release] diff --git a/src/utils/question.rs b/src/utils/question.rs index a91c3c2..27eb7bb 100644 --- a/src/utils/question.rs +++ b/src/utils/question.rs @@ -163,6 +163,7 @@ impl<'a, T: Default> ChoicePrompt<'a, T> { pub fn ask(mut self) -> crate::Result { let message = self.prompt; + #[cfg(not(feature = "allow_piped_choice"))] if !stdin().is_terminal() { eprintln!("{}", message); eprintln!("Pass --yes to proceed"); @@ -259,6 +260,7 @@ impl<'a> Confirmation<'a> { (Some(placeholder), Some(subs)) => Cow::Owned(self.prompt.replace(placeholder, subs)), }; + #[cfg(not(feature = "allow_piped_choice"))] if !stdin().is_terminal() { eprintln!("{}", message); eprintln!("Pass --yes to proceed"); diff --git a/tests/integration.rs b/tests/integration.rs index ae6606c..1c43736 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -270,6 +270,43 @@ fn multiple_files_with_conflict_and_choce_to_not_overwrite( assert_same_directory(after, after_backup, false); } +#[cfg(feature = "allow_piped_choice")] +#[proptest(cases = 25)] +fn multiple_files_with_conflict_and_choce_to_rename( + ext: DirectoryExtension, + #[any(size_range(0..1).lift())] extra_extensions: Vec, + #[strategy(0u8..3)] depth: u8, +) { + let dir = tempdir().unwrap(); + let dir = dir.path(); + + let before = &dir.join("before"); + let before_dir = &before.join("dir"); + fs::create_dir_all(before_dir).unwrap(); + create_random_files(before_dir, depth, &mut SmallRng::from_entropy()); + + let after = &dir.join("after"); + let after_dir = &after.join("dir"); + fs::create_dir_all(after_dir).unwrap(); + create_random_files(after_dir, depth, &mut SmallRng::from_entropy()); + + let archive = &dir.join(format!("archive.{}", merge_extensions(&ext, extra_extensions))); + ouch!("-A", "c", before_dir, archive); + + let after_renamed_dir = &after.join("dir_1"); + assert_eq!(false, after_renamed_dir.exists()); + + crate::utils::cargo_bin() + .arg("decompress") + .arg(archive) + .arg("-d") + .arg(after) + .write_stdin("r") + .assert() + .success(); + + assert_same_directory(before_dir, after_renamed_dir, false); +} #[cfg(feature = "unrar")] #[test]