2016-12-12 16:34:43 +00:00
|
|
|
|
#! @shell@
|
|
|
|
|
set -e
|
|
|
|
|
set -o pipefail
|
|
|
|
|
export PATH=@path@:$PATH
|
|
|
|
|
|
2016-12-15 20:52:53 +00:00
|
|
|
|
evalNix() {
|
2019-05-01 11:26:04 +00:00
|
|
|
|
nix-instantiate --eval --strict "${extraEvalFlags[@]}" -E "with import <darwin> {}; $*"
|
2016-12-15 20:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evalAttrs() {
|
2018-03-29 20:34:35 +00:00
|
|
|
|
evalNix "builtins.concatStringsSep \"\\n\" (builtins.attrNames $*)"
|
2016-12-15 20:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evalOpt() {
|
2018-03-29 20:34:35 +00:00
|
|
|
|
evalNix "options.$option.$*" 2>/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evalOptText() {
|
|
|
|
|
eval printf "$(evalNix "options.$option.$*" 2>/dev/null)" 2>/dev/null
|
|
|
|
|
echo
|
2016-12-15 20:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 07:31:12 +00:00
|
|
|
|
showSyntax() {
|
2019-05-01 11:26:04 +00:00
|
|
|
|
echo "$0: [-I path] <option>" >&2
|
2018-03-29 20:34:35 +00:00
|
|
|
|
eval printf "$(evalAttrs "options")"
|
2017-05-12 07:31:12 +00:00
|
|
|
|
echo
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 20:52:53 +00:00
|
|
|
|
# Parse the command line.
|
|
|
|
|
origArgs=("$@")
|
2019-05-01 11:26:04 +00:00
|
|
|
|
extraEvalFlags=()
|
2016-12-15 20:52:53 +00:00
|
|
|
|
option=
|
|
|
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
|
i="$1"; shift 1
|
|
|
|
|
case "$i" in
|
|
|
|
|
--help)
|
|
|
|
|
showSyntax
|
|
|
|
|
;;
|
2019-05-01 11:26:04 +00:00
|
|
|
|
-I)
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
echo "$0: ‘$i’ requires an argument"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
j="$1"; shift 1
|
|
|
|
|
extraEvalFlags+=("$i" "$j")
|
|
|
|
|
;;
|
2016-12-15 20:52:53 +00:00
|
|
|
|
*)
|
|
|
|
|
option="$i"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -z "$option" ]; then showSyntax; fi
|
|
|
|
|
|
2016-12-15 21:03:06 +00:00
|
|
|
|
if [ "$(evalOpt "_type")" = '"option"' ]; then
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo "Value:"
|
2016-12-15 21:03:06 +00:00
|
|
|
|
evalOpt "value" || echo "no value"
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "Default:"
|
2018-03-29 20:34:35 +00:00
|
|
|
|
evalOpt "default" || evalOptText "defaultText" || echo "no default"
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "Example:"
|
2021-10-23 13:05:52 +00:00
|
|
|
|
if [ "$(evalOpt "example._type")" = '"literalExpression"' ]; then
|
2018-03-29 20:34:35 +00:00
|
|
|
|
evalOptText "example.text" || echo "no example"
|
|
|
|
|
else
|
|
|
|
|
evalOpt "example" || echo "no example"
|
|
|
|
|
fi
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo
|
|
|
|
|
echo "Description:"
|
2018-03-29 20:34:35 +00:00
|
|
|
|
evalOptText "description" || echo "no description"
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo
|
|
|
|
|
else
|
2018-03-29 20:34:35 +00:00
|
|
|
|
eval printf "$(evalAttrs "options.$option")" 2>/dev/null
|
2016-12-15 20:52:53 +00:00
|
|
|
|
echo
|
|
|
|
|
fi
|