nuclei: 3.3.5 -> 3.3.6 (#358083)
[NixPkgs.git] / maintainers / scripts / get-maintainer.sh
blob3061d2ccc72f9a1f97806cd587133de6760f00db
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.
8 set -euo pipefail
10 declare -A SELECTORS=( [handle]= [email]= [github]= [githubId]= [matrix]= [name]= )
11 HELP_MESSAGE="usage: '$0' [selector] value
12 examples:
13 get-maintainer.sh nicoo
14 get-maintainer.sh githubId 1155801
16 \`selector\` defaults to 'handle', can be one of:
17 ${!SELECTORS[*]}
20 MAINTAINERS_DIR="$(dirname "$0")/.."
22 die() {
23 tput setaf 1 # red
24 echo "'$0': $*"
25 tput setaf 0 # back to black
26 exit 1
29 listAsJSON() {
30 nix-instantiate --eval --strict --json "${MAINTAINERS_DIR}/maintainer-list.nix"
33 parseArgs() {
34 [ $# -gt 0 -a $# -lt 3 ] || {
35 echo "$HELP_MESSAGE"
36 die "invalid number of arguments (must be 1 or 2)"
39 if [ $# -eq 1 ]; then
40 selector=handle
41 else
42 selector="$1"
43 shift
45 [ -z "${SELECTORS[$selector]-n}" ] || {
46 echo "Valid selectors are:" "${!SELECTORS[@]}" >&2
47 die "invalid selector '$selector'"
50 value="$1"
51 shift
54 query() {
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` ?
60 local select
61 case "$selector" in
62 githubId)
63 select="select(.${selector} == $value)"
66 select="select(.${selector} == \"$value\")"
67 esac
69 echo "$explode | $select"
72 parseArgs "$@"
73 listAsJSON | jq -e "$(query)"