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

60 lines
993 B
Bash
Raw Normal View History

2016-12-12 16:34:43 +00:00
#! @shell@
set -e
set -o pipefail
export PATH=@path@:$PATH
showSyntax() {
2016-12-15 21:03:06 +00:00
echo "$0: <option>" >&2
exec man darwin-option
2016-12-15 20:52:53 +00:00
exit 1
2016-12-12 16:34:43 +00:00
}
2016-12-15 20:52:53 +00:00
evalNix() {
nix-instantiate --eval --strict -E "with import <darwin> {}; $@"
}
evalAttrs() {
evalNix "builtins.concatStringsSep \"\n\" (builtins.attrNames $@)"
}
evalOpt() {
2016-12-15 21:03:06 +00:00
evalNix "options.$option.$@" 2>/dev/null
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:"
2016-12-15 21:03:06 +00:00
evalOpt "default" || echo "no default"
2016-12-15 20:52:53 +00:00
echo
echo "Example:"
2016-12-15 21:03:06 +00:00
evalOpt "example" || echo "no example"
2016-12-15 20:52:53 +00:00
echo
echo "Description:"
2016-12-15 21:03:06 +00:00
eval printf $(evalOpt "description") || echo "no description"
2016-12-15 20:52:53 +00:00
echo
else
eval printf $(evalAttrs "options.$option")
echo
fi