mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
cp: move option check to uumain and use show_usage_error
- add test for conflicting options `--backup` and `--no-clobber`
This commit is contained in:
parent
a8a1ec7faf
commit
25ed5eeb0e
2 changed files with 18 additions and 11 deletions
|
@ -463,6 +463,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.get_matches_from(args);
|
||||
|
||||
let options = crash_if_err!(EXIT_ERR, Options::from_matches(&matches));
|
||||
|
||||
if options.overwrite == OverwriteMode::NoClobber && options.backup != BackupMode::NoBackup {
|
||||
show_usage_error!("options --backup and --no-clobber are mutually exclusive");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let paths: Vec<String> = matches
|
||||
.values_of(OPT_PATHS)
|
||||
.map(|v| v.map(ToString::to_string).collect())
|
||||
|
@ -593,17 +599,6 @@ impl Options {
|
|||
|
||||
let overwrite = OverwriteMode::from_matches(matches);
|
||||
|
||||
if overwrite == OverwriteMode::NoClobber && backup_mode != BackupMode::NoBackup {
|
||||
show_error!(
|
||||
"options --backup and --no-clobber are mutually exclusive\n\
|
||||
Try '{} --help' for more information.",
|
||||
executable!()
|
||||
);
|
||||
return Err(Error::Error(
|
||||
"options --backup and --no-clobber are mutually exclusive".to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
// Parse target directory options
|
||||
let no_target_dir = matches.is_present(OPT_NO_TARGET_DIRECTORY);
|
||||
let target_dir = matches
|
||||
|
|
|
@ -539,6 +539,18 @@ fn test_cp_backup_off() {
|
|||
assert!(!at.file_exists(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_backup_no_clobber_conflicting_options() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
ucmd.arg("--backup")
|
||||
.arg("--no-clobber")
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.fails()
|
||||
.stderr_is("cp: options --backup and --no-clobber are mutually exclusive\nTry 'cp --help' for more information.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_deref_conflicting_options() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue