1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 00:37:00 +00:00
nix-darwin/pkgs/nix-tools/darwin-option.sh
Chris Hodapp 8637e7a92f Better no-args darwin-options output
There isn't a man page and it's useful to print out the list of
top-level keys.
2017-05-12 00:34:49 -07:00

59 lines
1,011 B
Bash
Executable file

#! @shell@
set -e
set -o pipefail
export PATH=@path@:$PATH
evalNix() {
nix-instantiate --eval --strict -E "with import <darwin> {}; $@"
}
evalAttrs() {
evalNix "builtins.concatStringsSep \"\n\" (builtins.attrNames $@)"
}
evalOpt() {
evalNix "options.$option.$@" 2>/dev/null
}
showSyntax() {
echo "$0: <option>" >&2
eval printf $(evalAttrs "options")
echo
exit 1
}
# 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
if [ "$(evalOpt "_type")" = '"option"' ]; then
echo "Value:"
evalOpt "value" || echo "no value"
echo
echo "Default:"
evalOpt "default" || echo "no default"
echo
echo "Example:"
evalOpt "example" || echo "no example"
echo
echo "Description:"
eval printf $(evalOpt "description") || echo "no description"
echo
else
eval printf $(evalAttrs "options.$option")
echo
fi