Last active
August 14, 2018 21:43
-
-
Save ponich/bf1023fc4523d19bcd3e7b32f7940346 to your computer and use it in GitHub Desktop.
options.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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