shred: accept shortcuts for stringly-enum arguments

This commit is contained in:
Ben Wiederhake 2024-04-01 08:06:18 +02:00
parent 1dd7d8e0db
commit 70d84e168c
2 changed files with 26 additions and 20 deletions

View file

@ -17,6 +17,7 @@ use std::path::{Path, PathBuf};
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::parse_size::parse_size_u64;
use uucore::shortcut_value_parser::ShortcutValueParser;
use uucore::{format_usage, help_about, help_section, help_usage, show_error, show_if_err};
const ABOUT: &str = help_about!("shred.md");
@ -315,11 +316,11 @@ pub fn uu_app() -> Command {
Arg::new(options::REMOVE)
.long(options::REMOVE)
.value_name("HOW")
.value_parser([
.value_parser(ShortcutValueParser::new([
options::remove::UNLINK,
options::remove::WIPE,
options::remove::WIPESYNC,
])
]))
.num_args(0..=1)
.require_equals(true)
.default_missing_value(options::remove::WIPESYNC)

View file

@ -17,6 +17,11 @@ fn test_invalid_remove_arg() {
new_ucmd!().arg("--remove=unknown").fails().code_is(1);
}
#[test]
fn test_ambiguous_remove_arg() {
new_ucmd!().arg("--remove=wip").fails().code_is(1);
}
#[test]
fn test_shred() {
let (at, mut ucmd) = at_and_ucmd!();
@ -49,15 +54,15 @@ fn test_shred_remove() {
#[test]
fn test_shred_remove_unlink() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_unlink";
at.touch(file);
ucmd.arg("--remove=unlink").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
// spell-checker:disable-next-line
for argument in ["--remove=unlink", "--remove=unlin", "--remove=u"] {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_unlink";
at.touch(file);
ucmd.arg(argument).arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
}
#[test]
@ -75,15 +80,15 @@ fn test_shred_remove_wipe() {
#[test]
fn test_shred_remove_wipesync() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_wipesync";
at.touch(file);
ucmd.arg("--remove=wipesync").arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
// spell-checker:disable-next-line
for argument in ["--remove=wipesync", "--remove=wipesyn", "--remove=wipes"] {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_shred_remove_wipesync";
at.touch(file);
ucmd.arg(argument).arg(file).succeeds();
// File was deleted
assert!(!at.file_exists(file));
}
}
#[test]