git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sébastien Guimmara" <sebastien.guimmara@gmail.com>
To: git@vger.kernel.org
Cc: "Sébastien Guimmara" <sebastien.guimmara@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH v5 1/6] generate-cmdlist: parse common group commands
Date: Sat,  9 May 2015 19:17:31 +0200	[thread overview]
Message-ID: <1431191856-10949-2-git-send-email-sebastien.guimmara@gmail.com> (raw)
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

  reply	other threads:[~2015-05-09 17:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-09 17:17 [PATCH v5 0/6] git help: group common commands by theme Sébastien Guimmara
2015-05-09 17:17 ` Sébastien Guimmara [this message]
2015-05-11  6:12   ` [PATCH v5 1/6] generate-cmdlist: parse common group commands Eric Sunshine
2015-05-09 17:17 ` [PATCH v5 2/6] help.c: output the typical Git workflow Sébastien Guimmara
2015-05-11  6:24   ` Eric Sunshine
2015-05-09 17:17 ` [PATCH v5 3/6] command-list.txt: group common commands by theme Sébastien Guimmara
2015-05-11  6:20   ` Eric Sunshine
2015-05-09 17:17 ` [PATCH v5 4/6] Makefile: update to new command-list.txt format Sébastien Guimmara
2015-05-11  6:44   ` Eric Sunshine
2015-05-09 17:17 ` [PATCH v5 5/6] new-command.txt: mention the common command groups Sébastien Guimmara
2015-05-11  6:47   ` Eric Sunshine
2015-05-09 17:17 ` [PATCH v5 6/6] cmd-list.perl: ignore all lines until [commands] Sébastien Guimmara
2015-05-11  6:59   ` Eric Sunshine
2015-05-11  5:52 ` [PATCH v5 0/6] git help: group common commands by theme Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431191856-10949-2-git-send-email-sebastien.guimmara@gmail.com \
    --to=sebastien.guimmara@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).