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
;;
o)
options="$options "$(printf "$OPTARG" | sed -e 's/,/ /g')""
options="$options,$OPTARG"
;;
esac
done
@ -148,29 +148,50 @@ option() {
shift
local negate=false
local variable=false
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 check="$(printf "$check" | cut -c 2-)"
local check="$(echo "$check" | cut -c 2-)"
;;
esac
local enabled=false
local option
for option in $options; do
local opt
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
local enabled=true
break
fi
done
if [ "$variable" = true ]; then
if [ "$enabled" = true ]; then
echo "$value"
return
else
echo "$default"
return
fi
fi
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
fi
if [ "$1" ]; then
[ "$enabled" = true ] && eval $@ || true
if [ "$enabled" = true ]; then
eval $@
fi
else
return $([ "$enabled" = true ])
fi

4
astronaut/hello.sat

@ -85,6 +85,10 @@ fi
# Abbreviation of the above
option test echo "Test option enabled"
# 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
rm "$dir_install/$dir_prefix/share/info/dir" # This file collides with some other packages.

Loading…
Cancel
Save