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

[PATCH v3 3/3] Add a help format 'usage' to provide brief command usage

From
Chris Webb <chris@arachsys.com>
Date
Jun 28, 2012, 06:58 UTC
Message-ID
<2fa0d1250c26eaa0d915e8d1cfbd10554a834460.1340866684.git.chris@arachsys.com>
In-Reply-To
<8d3c71d21710c66e4d5560cec958552b69a22338.1340866684.git.chris@arachsys.com>

Configuring the new help.format = usage makes git foo --help exactly equivalent to git foo -h, displaying brief command-line usage info instead of full documentation in the form of a man/html page.

This is useful on stripped-down servers where man pages and viewer aren't present, or if your fingers are trained to type COMMAND --help instead of COMMAND -h to get usage info and the man page behaviour is disturbing.

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 builtin/help.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/builtin/help.c b/builtin/help.c
index 92f2349..0df5bbf 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -31,7 +31,8 @@ enum help_format {
 	HELP_FORMAT_NONE,
 	HELP_FORMAT_MAN,
 	HELP_FORMAT_INFO,
-	HELP_FORMAT_WEB
+	HELP_FORMAT_WEB,
+	HELP_FORMAT_USAGE
 };
 
 static char *html_path = NULL;
@@ -46,11 +47,12 @@ static struct option builtin_help_options[] = {
 			HELP_FORMAT_WEB),
 	OPT_SET_INT('i', "info", &help_format, "show info page",
 			HELP_FORMAT_INFO),
+	OPT_SET_INT('u', "usage", &help_format, "show usage", HELP_FORMAT_USAGE),
 	OPT_END(),
 };
 
 static const char * const builtin_help_usage[] = {
-	"git help [--all] [--man|--web|--info] [command]",
+	"git help [--all] [--man|--web|--info|--usage] [command]",
 	NULL
 };
 
@@ -62,6 +64,8 @@ static enum help_format parse_help_format(const char *format)
 		return HELP_FORMAT_INFO;
 	if (!strcmp(format, "web") || !strcmp(format, "html"))
 		return HELP_FORMAT_WEB;
+	if (!strcmp(format, "usage"))
+		return HELP_FORMAT_USAGE;
 	die(_("unrecognized help format '%s'"), format);
 }
 
@@ -431,6 +435,11 @@ static void show_html_page(const char *git_cmd)
 	open_html(page_path.buf);
 }
 
+static void show_usage(const char *git_cmd)
+{
+	execl_git_cmd(git_cmd, "-h", NULL);
+}
+
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	int nongit;
@@ -482,6 +491,9 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	case HELP_FORMAT_WEB:
 		show_html_page(argv[0]);
 		break;
+	case HELP_FORMAT_USAGE:
+		show_usage(argv[0]);
+		break;
 	}
 
 	return 0;
-- 
1.7.10
Previous: Chris WebbNext: Junio C Hamano
Message 5 of 6 in “Add config variable to set HTML path for git-help --web”
  1. 1/3 Add config variable to set HTML path for git-help --webChris Webb, Jun 28, 2012
  2. 2/3 Allow help.htmlpath to be a URL prefixChris Webb, Jun 28, 2012
  3. Junio C HamanoJun 28, 2012
  4. Chris WebbJun 28, 2012
  5. 3/3 Add a help format 'usage' to provide brief command usageChris Webb, Jun 28, 2012
  6. Junio C HamanoJun 28, 2012

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.