From 0941166c9c685eeaf9a5607fa50c0790c8546440 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Thu, 3 Oct 2019 14:39:23 -0300 Subject: [PATCH] Fix regex checks --- src/arg.sh | 3 ++- src/main.sh | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/arg.sh b/src/arg.sh index d422dca..7c7d513 100644 --- a/src/arg.sh +++ b/src/arg.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -ARG_REGEX="<[a-zA-Z_]+([- ]?\w+)*>" +ARG_REGEX_WITHOUT_BRACKETS="[a-zA-Z_]+([- ]?\w+)*" +ARG_REGEX="<${ARG_REGEX_WITHOUT_BRACKETS}>" ARG_DELIMITER="\f" ARG_DELIMITER_2="\v" ARG_DELIMITER_3="\r" diff --git a/src/main.sh b/src/main.sh index 1e07154..23d86cc 100644 --- a/src/main.sh +++ b/src/main.sh @@ -39,22 +39,17 @@ handler::main() { fi escaped_arg="$(echo "$arg" | tr '-' '_' | tr ' ' '_')" - if [[ $escaped_arg =~ $ARG_REGEX ]]; then - cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")" - arg="$escaped_arg" - else - exit 1 + if ! [[ $escaped_arg =~ $ARG_REGEX_WITHOUT_BRACKETS ]]; then + exit 1 fi + cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")" + arg="$escaped_arg" value="$(arg::pick "$arg" "$cheat" || echo "")" - if [[ $arg =~ $ARG_REGEX ]]; then - if [ -z "$value" ]; then - echoerr "Unable to fetch suggestions for '$arg'!" - exit 0 - fi - else - exit 1 + if [ -z "$value" ]; then + echoerr "Unable to fetch suggestions for '$arg'!" + exit 1 fi eval "local $arg"='$value'