From 35ecf8f28abfd95114cac6bb7b535fde2f8c33d9 Mon Sep 17 00:00:00 2001 From: Nikolay Pronchev Date: Thu, 29 Aug 2024 16:11:10 +0300 Subject: [PATCH] Fix "auto" value for _accept_* configurations --- parser.sh | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/parser.sh b/parser.sh index 2de30bb..0de4165 100755 --- a/parser.sh +++ b/parser.sh @@ -139,19 +139,14 @@ _is_valid_var_name() { _command_required() { [ "$_accept_command" = "none" ] && return 1 [ "$_accept_command" != "auto" ] && return 0 + [ "$_mapped_commands_count" -gt 0 ] +} - _i=1 - while [ "$_i" -le "$_mapped_commands_count" ]; do - _command_auto_mapped=$(_var_value "_commands_${_i}_auto") - - if _is_not "$_command_auto_mapped"; then - return 0 - fi - - _i=$(_math "$_i + 1") - done - - return 1 +_mapped_options_only() { + [ "$_accept_options" = "none" ] && return 1 + [ "$_accept_options" = "any" ] && return 1 + [ "$_accept_options" = "mapped_only" ] && return 0 + [ "$_mapped_options_count" -gt 0 ] } _map_command() { @@ -714,7 +709,7 @@ _use_option() { _option_index=$(_get_mapped_option_index_by_alias "$1") if [ -z "$_option_index" ]; then - if [ "$_accept_options" = "mapped_only" ]; then + if _mapped_options_only; then _err "Unknown option: $1." else _map_option_auto "$1"