-
-
Notifications
You must be signed in to change notification settings - Fork 95
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Support for these flag notations can probably be achieved easily if we add a normalization function before calling parse_requirements:
Changing it to something like this:
normalize_input # this function will set a new array named $input
parse_requirements "${input[@]}"Possible implementation
#!/usr/bin/env bash
normalize_input() {
local arg flags
while [[ $# -gt 0 ]]; do
arg="$1"
if [[ $arg =~ ^(--[^=]+)=(.+)$ ]]; then
input+=("${BASH_REMATCH[1]}")
input+=("${BASH_REMATCH[2]}")
elif [[ $arg =~ ^(-[^=])=(.+)$ ]]; then
input+=("${BASH_REMATCH[1]}")
input+=("${BASH_REMATCH[2]}")
elif [[ $arg =~ ^-([^-].+)$ ]]; then
flags="${BASH_REMATCH[1]}"
for (( i=0 ; i < ${#flags} ; i++ )); do
input+=("-${flags:i:1}")
done
else
input+=("$arg")
fi
shift
done
}
declare -a input
normalize_input "$@"
for value in "${input[@]}"; do
echo ": $value"
doneOutput
$ ./test.sh -a -b arg -cde -f=arg --flag=arg -a=b=c --flag=anything=goes
: -a
: -b
: arg
: -c
: -d
: -e
: -f
: arg
: --flag
: arg
: -a
: b=c
: --flag
: anything=goesMetadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request