diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fdd45c..23186f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixes Makefile - Fixes -f- not to be interpreted as -f -- +- Fixes -f-flag not to be interpreted as -f --flag ## [3.3.1] - 2024-07-30 diff --git a/lib/getoptions_base.sh b/lib/getoptions_base.sh index 8aae4fa..db28176 100644 --- a/lib/getoptions_base.sh +++ b/lib/getoptions_base.sh @@ -147,7 +147,7 @@ getoptions() { [ "$_alt" ] || { [ "$_opts" ] && _op "-[$_opts]?*" "" ";;" [ ! "$_flags" ] || _op "-[$_flags]?*" - "OPTARG= ;;" \ - '[ "$2" = -- ] && set -- "$1" unknown -- && '"$_rest=x; " + 'case $2 in --*) set -- "$1" unknown "$2" && '"$_rest=x; esac;" } [ "$_plus" ] && { [ "$_nflags" ] && _op "+[$_nflags]?*" + "unset OPTARG ;;" diff --git a/spec/getoptions_base_spec.sh b/spec/getoptions_base_spec.sh index 57d7b7c..c218e6a 100644 --- a/spec/getoptions_base_spec.sh +++ b/spec/getoptions_base_spec.sh @@ -140,6 +140,15 @@ Describe "getoptions()" End End + Context "when the combined short option contains -" + parser_definition() { setup ARGS; flag FLAG -f --flag; } + It "displays error" + When run parse -f-flag + The stderr should eq "Unrecognized option: --flag" + The status should be failure + End + End + Context "when specified unknown long option" parser_definition() { setup ARGS; } It "displays error"