completion: implement and use --list-cmds=main,others
[git/git.git] / generate-cmdlist.sh
CommitLineData
82aec45b
ES
1#!/bin/sh
2
f318d739
NTND
3die () {
4 echo "$@" >&2
5 exit 1
6}
7
8command_list () {
cfb22a02 9 grep -v '^#' "$1"
f318d739
NTND
10}
11
12get_categories () {
13 tr ' ' '\n'|
14 grep -v '^$' |
15 sort |
16 uniq
17}
18
19category_list () {
20 command_list "$1" |
21 cut -c 40- |
22 get_categories
23}
24
75ba897e
NTND
25get_synopsis () {
26 sed -n '
27 /^NAME/,/'"$1"'/H
28 ${
29 x
30 s/.*'"$1"' - \(.*\)/N_("\1")/
31 p
32 }' "Documentation/$1.txt"
33}
34
f318d739
NTND
35define_categories () {
36 echo
37 echo "/* Command categories */"
38 bit=0
39 category_list "$1" |
40 while read cat
41 do
42 echo "#define CAT_$cat (1UL << $bit)"
43 bit=$(($bit+1))
44 done
45 test "$bit" -gt 32 && die "Urgh.. too many categories?"
46}
47
48print_command_list () {
49 echo "static struct cmdname_help command_list[] = {"
50
51 command_list "$1" |
52 while read cmd rest
53 do
54 printf " { \"$cmd\", $(get_synopsis $cmd), 0"
55 for cat in $(echo "$rest" | get_categories)
56 do
57 printf " | CAT_$cat"
58 done
59 echo " },"
60 done
61 echo "};"
62}
63
7513595a 64echo "/* Automatically generated by generate-cmdlist.sh */
82aec45b 65struct cmdname_help {
f318d739
NTND
66 const char *name;
67 const char *help;
cfb22a02 68 uint32_t category;
82aec45b 69};
f318d739 70"
60f487ac
NTND
71define_categories "$1"
72echo
73print_command_list "$1"