Browse Source

Adding support for options with custom values

master
mid-kid 9 years ago
parent
commit
daf4c71596
  1. 33
      astronaut/astronaut
  2. 4
      astronaut/hello.sat

33
astronaut/astronaut

@ -78,7 +78,7 @@ while getopts "h?s:b:i:r:p:IcCdvo:" opt; do
_vcs_only=true _vcs_only=true
;; ;;
o) o)
options="$options "$(printf "$OPTARG" | sed -e 's/,/ /g')"" options="$options,$OPTARG"
;; ;;
esac esac
done done
@ -148,29 +148,50 @@ option() {
shift shift
local negate=false local negate=false
local variable=false
case "$check" in case "$check" in
*=*)
local variable=true
local default="$(echo "$check" | cut -d '=' -f 2)"
local check="$(echo "$check" | cut -d '=' -f 1)"
;;
!*) !*)
local negate=true local negate=true
local check="$(printf "$check" | cut -c 2-)" local check="$(echo "$check" | cut -c 2-)"
;; ;;
esac esac
local enabled=false local enabled=false
local option local opt
for option in $options; do local IFS=','; for opt in $options; do
local option="$(echo "$opt" | cut -d '=' -f 1)"
local value="$(echo "$opt" | cut -d '=' -f 2)"
if [ "$option" = "$check" ]; then if [ "$option" = "$check" ]; then
local enabled=true local enabled=true
break break
fi fi
done done
if [ "$variable" = true ]; then
if [ "$enabled" = true ]; then
echo "$value"
return
else
echo "$default"
return
fi
fi
if [ "$negate" = true ]; then if [ "$negate" = true ]; then
# Shitty way to do a simple "NOT" operation (come on, it's just one operation on most cpus). # Shitty way to do a simple "NOT" operation.
[ "$enabled" = true ] && local enabled=false || local enabled=true [ "$enabled" = true ] && local enabled=false || local enabled=true
fi fi
if [ "$1" ]; then if [ "$1" ]; then
[ "$enabled" = true ] && eval $@ || true if [ "$enabled" = true ]; then
eval $@
fi
else else
return $([ "$enabled" = true ]) return $([ "$enabled" = true ])
fi fi

4
astronaut/hello.sat

@ -85,6 +85,10 @@ fi
# Abbreviation of the above # Abbreviation of the above
option test echo "Test option enabled" option test echo "Test option enabled"
# Bangs ("!") negate the operation. # Bangs ("!") negate the operation.
#option !test echo "Test option disabled"
# Options with arguments.
echo "Value of option test2 = $(option "test2=default value")"
make DESTDIR="$dir_install" install make DESTDIR="$dir_install" install
rm "$dir_install/$dir_prefix/share/info/dir" # This file collides with some other packages. rm "$dir_install/$dir_prefix/share/info/dir" # This file collides with some other packages.

Loading…
Cancel
Save