summaryrefslogtreecommitdiff
path: root/generate-cmdlist.sh
diff options
context:
space:
mode:
authorLibravatar Nguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-05-10 10:46:41 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-05-10 19:52:47 +0900
commitf318d7391592f153d1682d01ebaa2d35e3b6ede7 (patch)
tree785605146328278f1b452c0c99ae0144ccfbbd51 /generate-cmdlist.sh
parentgenerate-cmds.sh: factor out synopsis extract code (diff)
downloadtgif-f318d7391592f153d1682d01ebaa2d35e3b6ede7.tar.xz
generate-cmds.sh: export all commands to command-list.h
The current generate-cmds.sh generates just enough to print "git help" output. That is, it only extracts help text for common commands. The script is now updated to extract help text for all commands and keep command classification a new file, command-list.h. This will be useful later: - "git help -a" could print a short summary of all commands instead of just the common ones. - "git" could produce a list of commands of one or more category. One of its use is to reduce another command classification embedded in git-completion.bash. The new file can be generated but is not used anywhere yet. The plan is we migrate away from common-cmds.h. Then we can kill off common-cmds.h build rules and generation code (and also delete duplicate content in command-list.h which we keep for now to not mess generate-cmds.sh up too much). PS. The new fixed column requirement on command-list.txt is technically not needed. But it helps simplify the code a bit at this stage. We could lift this restriction later if we want to. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'generate-cmdlist.sh')
-rwxr-xr-xgenerate-cmdlist.sh67
1 files changed, 63 insertions, 4 deletions
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 31b6d886cb..870d3b626a 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -1,5 +1,27 @@
#!/bin/sh
+die () {
+ echo "$@" >&2
+ exit 1
+}
+
+command_list () {
+ sed '1,/^### command list/d;/^#/d' "$1"
+}
+
+get_categories () {
+ tr ' ' '\n'|
+ grep -v '^$' |
+ sort |
+ uniq
+}
+
+category_list () {
+ command_list "$1" |
+ cut -c 40- |
+ get_categories
+}
+
get_synopsis () {
sed -n '
/^NAME/,/'"$1"'/H
@@ -10,14 +32,51 @@ get_synopsis () {
}' "Documentation/$1.txt"
}
+define_categories () {
+ echo
+ echo "/* Command categories */"
+ bit=0
+ category_list "$1" |
+ while read cat
+ do
+ echo "#define CAT_$cat (1UL << $bit)"
+ bit=$(($bit+1))
+ done
+ test "$bit" -gt 32 && die "Urgh.. too many categories?"
+}
+
+print_command_list () {
+ echo "static struct cmdname_help command_list[] = {"
+
+ command_list "$1" |
+ while read cmd rest
+ do
+ printf " { \"$cmd\", $(get_synopsis $cmd), 0"
+ for cat in $(echo "$rest" | get_categories)
+ do
+ printf " | CAT_$cat"
+ done
+ echo " },"
+ done
+ echo "};"
+}
+
echo "/* Automatically generated by generate-cmdlist.sh */
struct cmdname_help {
- char name[16];
- char help[80];
- unsigned char group;
+ const char *name;
+ const char *help;
+ uint32_t group;
};
+"
+if test -z "$2"
+then
+ define_categories "$1"
+ echo
+ print_command_list "$1"
+ exit 0
+fi
-static const char *common_cmd_groups[] = {"
+echo "static const char *common_cmd_groups[] = {"
grps=grps$$.tmp
match=match$$.tmp