help: introduce option --exclude-guides
Introduce option --exclude-guides to the help command. With this option being passed, "git help" will open man pages only for actual commands. Since we know it is a command, we can use function help_unknown_command to give the user advice on typos. Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ralf Thielow committed
Aug 26, 2016 at 19:58 UTC
af74128f4a447678daae4d59069fba8a0c797210
2 files changed
+67
-7
builtin/help.c
+23
-7
@@ -37,8 +37,10 @@ static int show_all = 0;
37
static int show_guides = 0;
38
static unsigned int colopts;
39
static enum help_format help_format = HELP_FORMAT_NONE;
40
+static int exclude_guides;
41
static struct option builtin_help_options[] = {
42
OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
43
+ OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")),
44
OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")),
45
OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
46
OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
@@ -426,10 +428,29 @@ static void list_common_guides_help(void)
428
putchar('\n');
429
}
430
431
+static const char *check_git_cmd(const char* cmd)
432
+{
433
+ char *alias;
434
+
435
+ if (is_git_command(cmd))
436
+ return cmd;
437
+
438
+ alias = alias_lookup(cmd);
439
+ if (alias) {
440
+ printf_ln(_("`git %s' is aliased to `%s'"), cmd, alias);
441
+ free(alias);
442
+ exit(0);
443
+ }
444
+
445
+ if (exclude_guides)
446
+ return help_unknown_cmd(cmd);
447
+
448
+ return cmd;
449
+}
450
+
451
int cmd_help(int argc, const char **argv, const char *prefix)
452
{
453
int nongit;
432
- char *alias;
454
enum help_format parsed_help_format;
455
456
argc = parse_options(argc, argv, prefix, builtin_help_options,
@@ -469,12 +490,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
490
if (help_format == HELP_FORMAT_NONE)
491
help_format = parse_help_format(DEFAULT_HELP_FORMAT);
492
472
- alias = alias_lookup(argv[0]);
473
- if (alias && !is_git_command(argv[0])) {
474
- printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias);
475
- free(alias);
476
- return 0;
477
- }
493
+ argv[0] = check_git_cmd(argv[0]);
494
495
switch (help_format) {
496
case HELP_FORMAT_NONE:
t/t0012-help.sh
new
+44
@@ -0,0 +1,44 @@
1
+#!/bin/sh
2
+
3
+test_description='help'
4
+
5
+. ./test-lib.sh
6
+
7
+configure_help () {
8
+ test_config help.format html &&
9
+
10
+ # Unless the path has "://" in it, Git tries to make sure
11
+ # the documentation directory locally exists. Avoid it as
12
+ # we are only interested in seeing an attempt to correctly
13
+ # invoke a help browser in this test.
14
+ test_config help.htmlpath test://html &&
15
+
16
+ # Name a custom browser
17
+ test_config browser.test.cmd ./test-browser &&
18
+ test_config help.browser test
19
+}
20
+
21
+test_expect_success "setup" '
22
+ # Just write out which page gets requested
23
+ write_script test-browser <<-\EOF
24
+ echo "$*" >test-browser.log
25
+ EOF
26
+'
27
+
28
+test_expect_success "works for commands and guides by default" '
29
+ configure_help &&
30
+ git help status &&
31
+ echo "test://html/git-status.html" >expect &&
32
+ test_cmp expect test-browser.log &&
33
+ git help revisions &&
34
+ echo "test://html/gitrevisions.html" >expect &&
35
+ test_cmp expect test-browser.log
36
+'
37
+
38
+test_expect_success "--exclude-guides does not work for guides" '
39
+ >test-browser.log &&
40
+ test_must_fail git help --exclude-guides revisions &&
41
+ test_must_be_empty test-browser.log
42
+'
43
+
44
+test_done