From 80df9053b3dafc99ea9fda3af8b2eb5d2d6b9bc6 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Wed, 5 Jul 2017 17:22:48 -0700 Subject: [PATCH] `count -h` should report 1 The count command should not treat any flag specially. Not even `-h` and `--help`. It should simply return a count of the number of arguments it received. Fixes #4189 --- CHANGELOG.md | 1 + src/builtin.cpp | 2 +- tests/count.err | 0 tests/count.in | 17 +++++++++++++++++ tests/count.out | 12 ++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/count.err create mode 100644 tests/count.in create mode 100644 tests/count.out diff --git a/CHANGELOG.md b/CHANGELOG.md index d542ff657..6a5ee319b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - `help` can now open the tutorial. - `echo -h` now correctly echoes `-h` (#4120). - Stop converting empty elements in MANPATH to "." (#4158). The behavior being changed was introduced in fish 2.6.0. +- `count -h` and `count --help` now return one (#4189). - Added completions for: - `as` (#4130). - `jest` (#4142). diff --git a/src/builtin.cpp b/src/builtin.cpp index fa2e0376f..2ffc017e3 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -491,7 +491,7 @@ bool builtin_exists(const wcstring &cmd) { return static_cast(builtin_look /// Is the command a keyword or a builtin we need to special-case the handling of `-h` and `--help`. static const wcstring_list_t help_builtins({L"for", L"while", L"function", L"if", L"end", L"switch", - L"case", L"count", L"printf"}); + L"case", L"printf"}); static bool cmd_needs_help(const wchar_t *cmd) { return contains(help_builtins, cmd); } /// Execute a builtin command diff --git a/tests/count.err b/tests/count.err new file mode 100644 index 000000000..e69de29bb diff --git a/tests/count.in b/tests/count.in new file mode 100644 index 000000000..683c54a69 --- /dev/null +++ b/tests/count.in @@ -0,0 +1,17 @@ +# Validate the behavior of the `count` command. + +echo '# no args' +count + +echo '# one args' +count x + +echo '# two args' +count x y + +echo '# args that look like flags or are otherwise special' +count -h +count --help +count -- +count -- abc +count def -- abc diff --git a/tests/count.out b/tests/count.out new file mode 100644 index 000000000..ca42bee04 --- /dev/null +++ b/tests/count.out @@ -0,0 +1,12 @@ +# no args +0 +# one args +1 +# two args +2 +# args that look like flags or are otherwise special +1 +1 +1 +2 +3