Fix regex checks

This commit is contained in:
Denis Isidoro 2019-10-03 14:39:23 -03:00
parent 7c767810e4
commit 0941166c9c
2 changed files with 9 additions and 13 deletions

View file

@ -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"

View file

@ -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'