Skip to content

Commit 2cc5ec6

Browse files
committed
wc: accept shortcuts for stringly-enum arguments
1 parent 88a7823 commit 2cc5ec6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/uu/wc/src/wc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use uucore::{
2929
error::{FromIo, UError, UResult},
3030
format_usage, help_about, help_usage,
3131
quoting_style::{escape_name, QuotingStyle},
32+
shortcut_value_parser::ShortcutValueParser,
3233
show,
3334
};
3435

@@ -439,7 +440,9 @@ pub fn uu_app() -> Command {
439440
.arg(
440441
Arg::new(options::TOTAL)
441442
.long(options::TOTAL)
442-
.value_parser(["auto", "always", "only", "never"])
443+
.value_parser(ShortcutValueParser::new([
444+
"auto", "always", "only", "never",
445+
]))
443446
.value_name("WHEN")
444447
.hide_possible_values(true)
445448
.help(concat!(

tests/by-util/test_wc.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ fn test_total_auto() {
521521
.args(&["lorem_ipsum.txt", "--total=auto"])
522522
.run()
523523
.stdout_is(" 13 109 772 lorem_ipsum.txt\n");
524+
new_ucmd!()
525+
.args(&["lorem_ipsum.txt", "--tot=au"])
526+
.run()
527+
.stdout_is(" 13 109 772 lorem_ipsum.txt\n");
524528

525529
new_ucmd!()
526530
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=auto"])
@@ -541,6 +545,13 @@ fn test_total_always() {
541545
" 13 109 772 lorem_ipsum.txt\n",
542546
" 13 109 772 total\n",
543547
));
548+
new_ucmd!()
549+
.args(&["lorem_ipsum.txt", "--total=al"])
550+
.run()
551+
.stdout_is(concat!(
552+
" 13 109 772 lorem_ipsum.txt\n",
553+
" 13 109 772 total\n",
554+
));
544555

545556
new_ucmd!()
546557
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=always"])
@@ -566,6 +577,13 @@ fn test_total_never() {
566577
" 13 109 772 lorem_ipsum.txt\n",
567578
" 18 204 1115 moby_dick.txt\n",
568579
));
580+
new_ucmd!()
581+
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=n"])
582+
.run()
583+
.stdout_is(concat!(
584+
" 13 109 772 lorem_ipsum.txt\n",
585+
" 18 204 1115 moby_dick.txt\n",
586+
));
569587
}
570588

571589
#[test]
@@ -579,6 +597,10 @@ fn test_total_only() {
579597
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=only"])
580598
.run()
581599
.stdout_is("31 313 1887\n");
600+
new_ucmd!()
601+
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--t=o"])
602+
.run()
603+
.stdout_is("31 313 1887\n");
582604
}
583605

584606
#[test]

0 commit comments

Comments
 (0)