34
HELP_FORMAT_WEB
35
};
36
37
-static const char *html_path;
37
+static enum help_action {
38
+ HELP_ACTION_ALL = 1,
39
+ HELP_ACTION_GUIDES,
40
+ HELP_ACTION_CONFIG,
41
+ HELP_ACTION_CONFIG_FOR_COMPLETION,
42
+} cmd_mode;
43
39
-static int show_all = 0;
40
-static int show_guides = 0;
41
-static int show_config;
44
+static const char *html_path;
45
static int verbose = 1;
46
static unsigned int colopts;
47
static enum help_format help_format = HELP_FORMAT_NONE;
48
static int exclude_guides;
49
static struct option builtin_help_options[] = {
47
- OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
50
+ OPT_CMDMODE('a', "all", &cmd_mode, N_("print all available commands"),
51
+ HELP_ACTION_ALL),
52
OPT_HIDDEN_BOOL(0, "exclude-guides", &exclude_guides, N_("exclude guides")),
49
- OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")),
50
- OPT_BOOL('c', "config", &show_config, N_("print all configuration variable names")),
51
- OPT_SET_INT_F(0, "config-for-completion", &show_config, "", 2, PARSE_OPT_HIDDEN),
53
OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
54
OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
55
HELP_FORMAT_WEB),
56
OPT_SET_INT('i', "info", &help_format, N_("show info page"),
57
HELP_FORMAT_INFO),
58
OPT__VERBOSE(&verbose, N_("print command description")),
59
+
60
+ OPT_CMDMODE('g', "guides", &cmd_mode, N_("print list of useful guides"),
61
+ HELP_ACTION_GUIDES),
62
+ OPT_CMDMODE('c', "config", &cmd_mode, N_("print all configuration variable names"),
63
+ HELP_ACTION_CONFIG),
64
+ OPT_CMDMODE_F(0, "config-for-completion", &cmd_mode, "",
65
+ HELP_ACTION_CONFIG_FOR_COMPLETION, PARSE_OPT_HIDDEN),
66
+
67
OPT_END(),
68
};
69
553
return cmd;
554
}
555
556
+static void no_extra_argc(int argc)
557
+{
558
+ if (argc)
559
+ usage_msg_opt(_("this option doesn't take any other arguments"),
560
+ builtin_help_usage, builtin_help_options);
561
+}
562
+
563
int cmd_help(int argc, const char **argv, const char *prefix)
564
{
565
int nongit;
570
builtin_help_usage, 0);
571
parsed_help_format = help_format;
572
557
- /* Incompatible options */
558
- if (show_all && show_config)
559
- usage_msg_opt(_("--config and --all cannot be combined"),
560
- builtin_help_usage, builtin_help_options);
561
-
562
- if (show_all && show_guides)
563
- usage_msg_opt(_("--config and --guides cannot be combined"),
564
- builtin_help_usage, builtin_help_options);
565
-
566
- if (show_config && show_guides)
567
- usage_msg_opt(_("--config and --guides cannot be combined"),
568
- builtin_help_usage, builtin_help_options);
569
-
570
- /* Options that take no further arguments */
571
- if (argc && show_config)
572
- usage_msg_opt(_("--config cannot be combined with command or guide names"),
573
- builtin_help_usage, builtin_help_options);
574
- if (argc && show_guides)
575
- usage_msg_opt(_("--guides cannot be combined with command or guide names"),
576
- builtin_help_usage, builtin_help_options);
577
-
578
- if (show_all) {
573
+ switch (cmd_mode) {
574
+ case HELP_ACTION_ALL:
575
git_config(git_help_config, NULL);
576
if (verbose) {
577
setup_pager();
581
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
582
load_command_list("git-", &main_cmds, &other_cmds);
583
list_commands(colopts, &main_cmds, &other_cmds);
588
- }
589
-
590
- if (show_guides)
584
+ printf("%s\n", _(git_more_info_string));
585
+ break;
586
+ case HELP_ACTION_GUIDES:
587
+ no_extra_argc(argc);
588
list_guides_help();
592
-
593
- if (show_all || show_guides) {
589
printf("%s\n", _(git_more_info_string));
590
return 0;
596
- }
597
-
598
- if (show_config) {
599
- int for_human = show_config == 1;
600
-
601
- if (!for_human) {
602
- list_config_help(for_human);
603
- return 0;
604
- }
591
+ case HELP_ACTION_CONFIG_FOR_COMPLETION:
592
+ list_config_help(0);
593
+ return 0;
594
+ case HELP_ACTION_CONFIG:
595
+ no_extra_argc(argc);
596
setup_pager();
606
- list_config_help(for_human);
597
+ list_config_help(1);
598
printf("\n%s\n", _("'git help config' for more information"));
599
return 0;
600
}