diff --git a/src/install/install.rs b/src/install/install.rs index fdefac429..a52f82846 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -50,6 +50,11 @@ pub fn uumain(args: Vec) -> i32 { let usage = opts.usage("Copy SOURCE to DEST or multiple SOURCE(s) to the existing\n \ DIRECTORY, while setting permission modes and owner/group"); + if let Err(s) = check_unimplemented(&matches) { + show_error!("Unimplemented feature: {}", s); + return 2; + } + let behaviour = match behaviour(&matches) { Ok(x) => x, Err(ret) => { @@ -100,7 +105,7 @@ fn opts() -> getopts::Options { components of the specified directories"); - // TODO implement flagd + // TODO implement flag opts.optflag("D", "", "create all leading components of DEST except the last, then copy\n \ SOURCE to DEST"); @@ -150,6 +155,46 @@ fn opts() -> getopts::Options { opts } +fn check_unimplemented(matches: &getopts::Matches) -> Result<(), &str> { + if matches.opt_present("backup") { + Err("--backup") + } else if matches.opt_present("b") { + Err("-b") + } else if matches.opt_present("compare") { + Err("--compare, -C") + } else if matches.opt_present("directory") { + Err("--directory, -d") + } else if matches.opt_present("D") { + Err("-D") + } else if matches.opt_present("group") { + Err("--group, -g") + } else if matches.opt_present("mode") { + Err("--mode, -m") + } else if matches.opt_present("owner") { + Err("--owner, -o") + } else if matches.opt_present("preserve-timestamps") { + Err("--preserve-timestamps, -p") + } else if matches.opt_present("strip") { + Err("--strip, -s") + } else if matches.opt_present("strip-program") { + Err("--strip-program") + } else if matches.opt_present("suffix") { + Err("--suffix, -S") + } else if matches.opt_present("target-directory") { + Err("--target-directory, -t") + } else if matches.opt_present("no-target-directory") { + Err("--no-target-directory, -T") + } else if matches.opt_present("verbose") { + Err("--verbose, -v") + } else if matches.opt_present("preserve-context") { + Err("--preserve-context, -P") + } else if matches.opt_present("context") { + Err("--context, -Z") + } else { + Ok(()) + } +} + fn behaviour(matches: &getopts::Matches) -> Result { let main_function = if matches.opt_present("version") { MainFunction::Version diff --git a/tests/test_install.rs b/tests/test_install.rs index 2105708a5..817f6d397 100644 --- a/tests/test_install.rs +++ b/tests/test_install.rs @@ -17,13 +17,13 @@ fn test_install_help() { assert_empty_stderr!(result); assert!(result.success); -// assert!(result.stdout.contains("Usage:")); + assert!(result.stdout.contains("Usage:")); } #[test] fn test_install_basic() { let (at, mut ucmd) = testing(UTIL_NAME); - let dir = "test_install_target_dir_dir"; + let dir = "test_install_target_dir_dir_a"; let file = "test_install_target_dir_file_a"; at.touch(file); @@ -36,3 +36,20 @@ fn test_install_basic() { assert!(!at.file_exists(file)); assert!(at.file_exists(&format!("{}/{}", dir, file))); } + +#[test] +fn test_install_unimplemented_arg() { + let (at, mut ucmd) = testing(UTIL_NAME); + let dir = "test_install_target_dir_dir_b"; + let file = "test_install_target_dir_file_b"; + let context_arg = "--context"; + + at.touch(file); + at.mkdir(dir); + let result = ucmd.arg(context_arg).arg(file).arg(dir).run(); + + assert!(!result.success); + assert!(result.stderr.contains("Unimplemented")); + + assert!(!at.file_exists(&format!("{}/{}", dir, file))); +}