Skip to content

Instantly share code, notes, and snippets.

@ponich
Last active August 14, 2018 21:43
Show Gist options
  • Select an option

  • Save ponich/bf1023fc4523d19bcd3e7b32f7940346 to your computer and use it in GitHub Desktop.

Select an option

Save ponich/bf1023fc4523d19bcd3e7b32f7940346 to your computer and use it in GitHub Desktop.
options.sh
#!/usr/bin/env bash
#option --h : Show help information
#option --p|php: PHP Version
#option --test|set-test-mode:Test mode enable
#option --DSDSA|dd:dsds
#option --v|--vv|--vvv|verbose
#option --debug
#option --http-root-path=/var/www :Http path
#option --set-mode= : Mode, require option
#option --set-mode= 2 : Mode, require option
#option --g =true
#option --v|version =213 df
declare -A OPTIONS
set_option_value(){
echo ""
}
get_option_value(){
echo ""
}
get_option_short_keys(){
echo $1
}
get_option_keys(){
echo ""
}
options(){
while read str; do
local isOption=$(echo ${str} | grep -oP '\#option\W+(\-\-[a-zA-Z0-9\|\-]{0,})(.*\=([a-zA-Z0-9\\\/\s]{0,}+))?(?:.*\:(.*))?')
if [ -z "${isOption}" ]; then
continue
fi
optstring=$(echo ${str} |\
grep -oP '\#option\W+(\-\-[a-zA-Z0-9\|\-]{0,})' |\
grep -oP '(\-\-[a-zA-Z0-9\|\-]{0,})')
get_option_short_keys ${optstring}
optvalue=$(echo ${str} | grep -oP '\#option\W+(\-\-[a-zA-Z0-9\|\-]{0,})(.*\=([a-zA-Z0-9\\\/\s-_]{0,}+))' |\
grep -oP '\=([a-zA-Z0-9-_\\\/\s]{0,}+)?' | grep -oP '[^\=](.*)')
optdescription=$(echo ${str} | grep -oP '\#option\W+(\-\-[a-zA-Z0-9\|\-]{0,}).*(?:.?\:(.*))?' |\
grep -oP '(?<=\:)+(?:.*)')
done <${0}
}
options
#\#option\W+(?<option_str>\-\-[a-zA-Z0-9\|\-]{0,})(.*\=(?<value_str>[a-zA-Z0-9\\\/\s]{0,}+))?(?:.*\:(?<description_str>.*))?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment