1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00
nix-darwin/pkgs/nix-tools/darwin-option.sh

69 lines
1.2 KiB
Bash
Raw Normal View History

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() {
nix-instantiate --eval --strict -E "with import <darwin> {}; $*"
2016-12-15 20:52:53 +00:00
}
evalAttrs() {
evalNix "builtins.concatStringsSep \"\\n\" (builtins.attrNames $*)"
2016-12-15 20:52:53 +00:00
}
evalOpt() {
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
}
showSyntax() {
echo "$0: <option>" >&2
eval printf "$(evalAttrs "options")"
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:"
evalOpt "default" || evalOptText "defaultText" || echo "no default"
2016-12-15 20:52:53 +00:00
echo
echo "Example:"
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:"
evalOptText "description" || echo "no description"
2016-12-15 20:52:53 +00:00
echo
else
eval printf "$(evalAttrs "options.$option")" 2>/dev/null
2016-12-15 20:52:53 +00:00
echo
fi