Add best practice of using __double_underscore_prefixed_vars

This commit is contained in:
Kevin van Zonneveld 2016-06-21 10:21:00 +02:00
parent 0487f12fff
commit ae230acc3b
3 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,7 @@
## master (Unreleased)
- Add best practice of using `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
- Make license more permissive by not requiring distribution of the LICENSE file if the copyright & attribution comments are left intact
- Respect `--no-color` by setting the NO_COLOR flag in `main.sh` (#25, thx @gdevenyi)
- Split out changelog into separate file

View File

@ -101,6 +101,8 @@ $ my_script some more args --blah
- In functions, use `local` before every variable declaration
- This project settles on two spaces for tabs
- Use `UPPERCASE_VARS` to indicate environment variables that can be controlled outside your script
- Use `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
## Frequently Asked Questions

View File

@ -55,7 +55,7 @@ NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected
# - `--` is respected as the separator between options and arguments
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
# you can use bash variables to work around this (so use ${HOME} instead)
read -r -d '' usage <<-'EOF' || true # exits non-zero when EOF encountered
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
-f --file [arg] Filename to process. Required.
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
-v Enable verbose mode, print script as it is executed
@ -111,7 +111,7 @@ function help () {
echo "" 1>&2
echo " ${@}" 1>&2
echo "" 1>&2
echo " ${usage}" 1>&2
echo " ${__usage}" 1>&2
echo "" 1>&2
exit 1
}
@ -157,7 +157,7 @@ while read line; do
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
eval "${varname}=\"${match}\""
fi
done <<< "${usage}"
done <<< "${__usage}"
# Allow long options like --this
opts="${opts}-:"