1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p jq ncurses
3 # shellcheck shell=bash
5 # Get a nixpkgs maintainer's metadata as a JSON object
6 # see HELP_MESSAGE just below, or README.md.
10 declare -A SELECTORS
=( [handle
]= [email
]= [github
]= [githubId
]= [matrix
]= [name
]= )
11 HELP_MESSAGE
="usage: '$0' [selector] value
13 get-maintainer.sh nicoo
14 get-maintainer.sh githubId 1155801
16 \`selector\` defaults to 'handle', can be one of:
20 MAINTAINERS_DIR
="$(dirname "$0")/.."
25 tput setaf
0 # back to black
30 nix-instantiate
--eval --strict --json "${MAINTAINERS_DIR}/maintainer-list.nix"
34 [ $# -gt 0 -a $# -lt 3 ] ||
{
36 die
"invalid number of arguments (must be 1 or 2)"
45 [ -z "${SELECTORS[$selector]-n}" ] ||
{
46 echo "Valid selectors are:" "${!SELECTORS[@]}" >&2
47 die
"invalid selector '$selector'"
55 # explode { a: A, b: B, ... } into A + {handle: a}, B + {handle: b}, ...
56 local explode
="to_entries[] | .value + { \"handle\": .key }"
58 # select matching items from the list
59 # TODO(nicoo): Support approximate matching for `name` ?
63 select="select(.${selector} == $value)"
66 select="select(.${selector} == \"$value\")"
69 echo "$explode | $select"
73 listAsJSON | jq
-e "$(query)"