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
2016-12-15 21:52:53 +01:00

58 lines
898 B
Bash
Executable file

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