git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 1/6] generate-cmdlist: parse common group commands

From
Sébastien Guimmara <sebastien.guimmara@gmail.com>
Date
May 9, 2015, 17:17 UTC
Message-ID
<1431191856-10949-2-git-send-email-sebastien.guimmara@gmail.com>
In-Reply-To
<1431191856-10949-1-git-send-email-sebastien.guimmara@gmail.com>
Parse the [common] block to create the array of group descriptions:
static char *common_cmd_groups[] = {
    N_("start a working area (see also: git help tutorial)"),
    N_("work on the current change (see also: git help everyday)"),
    N_("examine the history and state (see also: git help revisions)"),
    N_("grow, mark and tweak your history"),
    N_("collaborate (see also: git help workflows)"),
};
then map each element of common_cmds[] to a group via its index:
static struct cmdname_help common_cmds[] = {
    {"add", N_("Add file contents to the index"), 1},
    {"branch", N_("List, create, or delete branches"), 4},
    {"checkout", N_("Checkout a branch or paths to the ..."), 4},
    {"clone", N_("Clone a repository into a new directory"), 0},
    {"commit", N_("Record changes to the repository"), 4},
    ...
};
so that 'git help' can print those commands grouped by theme.

Only commands tagged with an attribute from [common] are emitted to common_cmds[].

[commit message by Sébastien Guimmara <sebastien.guimmara@gmail.com>]
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 generate-cmdlist.awk | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 generate-cmdlist.awk
diff --git a/generate-cmdlist.awk b/generate-cmdlist.awk
new file mode 100644
index 0000000..cbaac88
--- /dev/null
+++ b/generate-cmdlist.awk
@@ -0,0 +1,38 @@
+BEGIN {
+	print "/* Automatically generated by generate-cmdlist.awk */\n"
+	print "struct cmdname_help {"
+	print "\tchar name[16];"
+	print "\tchar help[80];"
+	print "\tunsigned char group;"
+	print "};\n"
+	print "static char *common_cmd_groups[] = {"
+}
+/^#/ || /^[ 	]*$/ { next }
+state == 2 {
+	for (i = 2; i <= NF; i++)
+		if (grp[$i]) {
+			f = "Documentation/"$1".txt"
+			while (getline s <f > 0)
+				if (match(s, $1" - ")) {
+					t = substr(s, length($1" - ") + 1)
+					break
+				}
+			close(f)
+			printf "\t{\"%s\", N_(\"%s\"), %s},\n",
+				substr($1, length("git-") + 1), t, grp[$i] - 1
+			break
+		}
+}
+/\[commands\]/ {
+	print "};\n\nstatic struct cmdname_help common_cmds[] = {"
+	state = 2
+}
+state == 1 {
+	grp[$1] = ++n
+	sub($1"[ 	][ 	]*", "")
+	printf "\tN_(\"%s\"),\n", $0
+}
+/\[common\]/ {
+	state = 1
+}
+END { print "};" }
-- 
2.4.0
Previous: Sébastien GuimmaraNext: Eric Sunshine
Message 2 of 14 in “git help: group common commands by theme”
  1. 0/6 git help: group common commands by themeSébastien Guimmara, May 9, 2015
  2. 1/6 generate-cmdlist: parse common group commandsSébastien Guimmara, May 9, 2015
  3. Eric SunshineMay 11, 2015
  4. 2/6 help.c: output the typical Git workflowSébastien Guimmara, May 9, 2015
  5. Eric SunshineMay 11, 2015
  6. 3/6 command-list.txt: group common commands by themeSébastien Guimmara, May 9, 2015
  7. Eric SunshineMay 11, 2015
  8. 4/6 Makefile: update to new command-list.txt formatSébastien Guimmara, May 9, 2015
  9. Eric SunshineMay 11, 2015
  10. 5/6 new-command.txt: mention the common command groupsSébastien Guimmara, May 9, 2015
  11. Eric SunshineMay 11, 2015
  12. 6/6 cmd-list.perl: ignore all lines until [commands]Sébastien Guimmara, May 9, 2015
  13. Eric SunshineMay 11, 2015
  14. Eric SunshineMay 11, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.