mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
cb37c35e33
Also drops the eval hacks in favour of jq.
74 lines
1.4 KiB
Bash
Executable file
74 lines
1.4 KiB
Bash
Executable file
#! @shell@
|
||
set -e
|
||
set -o pipefail
|
||
export PATH=@path@:$PATH
|
||
|
||
evalNix() {
|
||
nix-instantiate --eval --strict "${extraEvalFlags[@]}" -E "with import <darwin> {}; $*" 2>/dev/null
|
||
}
|
||
|
||
evalOpt() {
|
||
evalNix "options.$option.$*"
|
||
}
|
||
|
||
evalOptAttrs() {
|
||
evalNix "builtins.concatStringsSep \"\\n\" (builtins.attrNames $*)" | jq -r .
|
||
}
|
||
|
||
evalOptText() {
|
||
evalNix "options.$option.$*" | jq -r .
|
||
}
|
||
|
||
showSyntax() {
|
||
echo "$0: [-I path] <option>" >&2
|
||
evalOptAttrs "options"
|
||
exit 1
|
||
}
|
||
|
||
# Parse the command line.
|
||
origArgs=("$@")
|
||
extraEvalFlags=()
|
||
option=
|
||
|
||
while [ "$#" -gt 0 ]; do
|
||
i="$1"; shift 1
|
||
case "$i" in
|
||
--help)
|
||
showSyntax
|
||
;;
|
||
-I)
|
||
if [ -z "$1" ]; then
|
||
echo "$0: ‘$i’ requires an argument"
|
||
exit 1
|
||
fi
|
||
j="$1"; shift 1
|
||
extraEvalFlags+=("$i" "$j")
|
||
;;
|
||
*)
|
||
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" || evalOptText "defaultText" || echo "no default"
|
||
echo
|
||
echo "Example:"
|
||
if [ "$(evalOpt "example._type")" = '"literalExpression"' ]; then
|
||
evalOptText "example.text" || echo "no example"
|
||
else
|
||
evalOpt "example" || echo "no example"
|
||
fi
|
||
echo
|
||
echo "Description:"
|
||
evalOptText "description.text" || echo "no description"
|
||
echo
|
||
else
|
||
evalOptAttrs "options.$option"
|
||
fi
|