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() {
|
2018-03-29 20:34:35 +00:00
|
|
|
nix-instantiate --eval --strict -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() {
|
|
|
|
echo "$0: <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=("$@")
|
|
|
|
option=
|
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
i="$1"; shift 1
|
|
|
|
case "$i" in
|
|
|
|
--help)
|
|
|
|
showSyntax
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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:"
|
2018-03-29 20:34:35 +00:00
|
|
|
if [ "$(evalOpt "example._type")" = '"literalExample"' ]; then
|
|
|
|
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
|