7
7
#include "exec-cmd.h"
8
8
#include "parse-options.h"
9
9
#include "run-command.h"
10
- #include "column.h"
11
10
#include "config-list.h"
12
11
#include "help.h"
13
12
#include "alias.h"
@@ -34,32 +33,52 @@ enum help_format {
34
33
HELP_FORMAT_WEB
35
34
};
36
35
37
- static const char * html_path ;
36
+ enum show_config_type {
37
+ SHOW_CONFIG_HUMAN ,
38
+ SHOW_CONFIG_VARS ,
39
+ SHOW_CONFIG_SECTIONS ,
40
+ };
41
+
42
+ static enum help_action {
43
+ HELP_ACTION_ALL = 1 ,
44
+ HELP_ACTION_GUIDES ,
45
+ HELP_ACTION_CONFIG ,
46
+ HELP_ACTION_CONFIG_FOR_COMPLETION ,
47
+ HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION ,
48
+ } cmd_mode ;
38
49
39
- static int show_all = 0 ;
40
- static int show_guides = 0 ;
41
- static int show_config ;
50
+ static const char * html_path ;
42
51
static int verbose = 1 ;
43
- static unsigned int colopts ;
44
52
static enum help_format help_format = HELP_FORMAT_NONE ;
45
53
static int exclude_guides ;
46
54
static struct option builtin_help_options [] = {
47
- OPT_BOOL ('a' , "all" , & show_all , N_ ("print all available commands" )),
55
+ OPT_CMDMODE ('a' , "all" , & cmd_mode , N_ ("print all available commands" ),
56
+ HELP_ACTION_ALL ),
48
57
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 ),
52
58
OPT_SET_INT ('m' , "man" , & help_format , N_ ("show man page" ), HELP_FORMAT_MAN ),
53
59
OPT_SET_INT ('w' , "web" , & help_format , N_ ("show manual in web browser" ),
54
60
HELP_FORMAT_WEB ),
55
61
OPT_SET_INT ('i' , "info" , & help_format , N_ ("show info page" ),
56
62
HELP_FORMAT_INFO ),
57
63
OPT__VERBOSE (& verbose , N_ ("print command description" )),
64
+
65
+ OPT_CMDMODE ('g' , "guides" , & cmd_mode , N_ ("print list of useful guides" ),
66
+ HELP_ACTION_GUIDES ),
67
+ OPT_CMDMODE ('c' , "config" , & cmd_mode , N_ ("print all configuration variable names" ),
68
+ HELP_ACTION_CONFIG ),
69
+ OPT_CMDMODE_F (0 , "config-for-completion" , & cmd_mode , "" ,
70
+ HELP_ACTION_CONFIG_FOR_COMPLETION , PARSE_OPT_HIDDEN ),
71
+ OPT_CMDMODE_F (0 , "config-sections-for-completion" , & cmd_mode , "" ,
72
+ HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION , PARSE_OPT_HIDDEN ),
73
+
58
74
OPT_END (),
59
75
};
60
76
61
77
static const char * const builtin_help_usage [] = {
62
- N_ ("git help [--all] [--guides] [--man | --web | --info] [<command>]" ),
78
+ N_ ("git help [-a|--all] [--[no-]verbose]]\n"
79
+ " [[-i|--info] [-m|--man] [-w|--web]] [<command>]" ),
80
+ N_ ("git help [-g|--guides]" ),
81
+ N_ ("git help [-c|--config]" ),
63
82
NULL
64
83
};
65
84
@@ -70,7 +89,7 @@ struct slot_expansion {
70
89
int found ;
71
90
};
72
91
73
- static void list_config_help (int for_human )
92
+ static void list_config_help (enum show_config_type type )
74
93
{
75
94
struct slot_expansion slot_expansions [] = {
76
95
{ "advice" , "*" , list_config_advices },
@@ -88,6 +107,8 @@ static void list_config_help(int for_human)
88
107
const char * * p ;
89
108
struct slot_expansion * e ;
90
109
struct string_list keys = STRING_LIST_INIT_DUP ;
110
+ struct string_list keys_uniq = STRING_LIST_INIT_DUP ;
111
+ struct string_list_item * item ;
91
112
int i ;
92
113
93
114
for (p = config_name_list ; * p ; p ++ ) {
@@ -118,34 +139,46 @@ static void list_config_help(int for_human)
118
139
for (i = 0 ; i < keys .nr ; i ++ ) {
119
140
const char * var = keys .items [i ].string ;
120
141
const char * wildcard , * tag , * cut ;
142
+ const char * dot = NULL ;
143
+ struct strbuf sb = STRBUF_INIT ;
121
144
122
- if (for_human ) {
145
+ switch (type ) {
146
+ case SHOW_CONFIG_HUMAN :
123
147
puts (var );
124
148
continue ;
149
+ case SHOW_CONFIG_SECTIONS :
150
+ dot = strchr (var , '.' );
151
+ break ;
152
+ case SHOW_CONFIG_VARS :
153
+ break ;
125
154
}
126
-
127
155
wildcard = strchr (var , '*' );
128
156
tag = strchr (var , '<' );
129
157
130
- if (!wildcard && !tag ) {
131
- puts ( var );
158
+ if (!dot && ! wildcard && !tag ) {
159
+ string_list_append ( & keys_uniq , var );
132
160
continue ;
133
161
}
134
162
135
- if (wildcard && !tag )
163
+ if (dot )
164
+ cut = dot ;
165
+ else if (wildcard && !tag )
136
166
cut = wildcard ;
137
167
else if (!wildcard && tag )
138
168
cut = tag ;
139
169
else
140
170
cut = wildcard < tag ? wildcard : tag ;
141
171
142
- /*
143
- * We may produce duplicates, but that's up to
144
- * git-completion.bash to handle
145
- */
146
- printf ("%.*s\n" , (int )(cut - var ), var );
172
+ strbuf_add (& sb , var , cut - var );
173
+ string_list_append (& keys_uniq , sb .buf );
174
+ strbuf_release (& sb );
175
+
147
176
}
148
177
string_list_clear (& keys , 0 );
178
+ string_list_remove_duplicates (& keys_uniq , 0 );
179
+ for_each_string_list_item (item , & keys_uniq )
180
+ puts (item -> string );
181
+ string_list_clear (& keys_uniq , 0 );
149
182
}
150
183
151
184
static enum help_format parse_help_format (const char * format )
@@ -349,8 +382,6 @@ static int add_man_viewer_info(const char *var, const char *value)
349
382
350
383
static int git_help_config (const char * var , const char * value , void * cb )
351
384
{
352
- if (starts_with (var , "column." ))
353
- return git_column_config (var , value , "help" , & colopts );
354
385
if (!strcmp (var , "help.format" )) {
355
386
if (!value )
356
387
return config_error_nonbool (var );
@@ -544,6 +575,13 @@ static const char *check_git_cmd(const char* cmd)
544
575
return cmd ;
545
576
}
546
577
578
+ static void no_extra_argc (int argc )
579
+ {
580
+ if (argc )
581
+ usage_msg_opt (_ ("this option doesn't take any other arguments" ),
582
+ builtin_help_usage , builtin_help_options );
583
+ }
584
+
547
585
int cmd_help (int argc , const char * * argv , const char * prefix )
548
586
{
549
587
int nongit ;
@@ -554,39 +592,36 @@ int cmd_help(int argc, const char **argv, const char *prefix)
554
592
builtin_help_usage , 0 );
555
593
parsed_help_format = help_format ;
556
594
557
- if ( show_all ) {
558
- git_config ( git_help_config , NULL );
595
+ switch ( cmd_mode ) {
596
+ case HELP_ACTION_ALL :
559
597
if (verbose ) {
560
598
setup_pager ();
561
599
list_all_cmds_help ();
562
600
return 0 ;
563
601
}
564
602
printf (_ ("usage: %s%s" ), _ (git_usage_string ), "\n\n" );
565
603
load_command_list ("git-" , & main_cmds , & other_cmds );
566
- list_commands (colopts , & main_cmds , & other_cmds );
567
- }
568
-
569
- if (show_config ) {
570
- int for_human = show_config == 1 ;
571
-
572
- if (!for_human ) {
573
- list_config_help (for_human );
574
- return 0 ;
575
- }
576
- setup_pager ();
577
- list_config_help (for_human );
578
- printf ("\n%s\n" , _ ("'git help config' for more information" ));
579
- return 0 ;
580
- }
581
-
582
- if (show_guides )
604
+ list_commands (& main_cmds , & other_cmds );
605
+ printf ("%s\n" , _ (git_more_info_string ));
606
+ break ;
607
+ case HELP_ACTION_GUIDES :
608
+ no_extra_argc (argc );
583
609
list_guides_help ();
584
-
585
- if (show_all || show_guides ) {
586
610
printf ("%s\n" , _ (git_more_info_string ));
587
- /*
588
- * We're done. Ignore any remaining args
589
- */
611
+ return 0 ;
612
+ case HELP_ACTION_CONFIG_FOR_COMPLETION :
613
+ no_extra_argc (argc );
614
+ list_config_help (SHOW_CONFIG_VARS );
615
+ return 0 ;
616
+ case HELP_ACTION_CONFIG_SECTIONS_FOR_COMPLETION :
617
+ no_extra_argc (argc );
618
+ list_config_help (SHOW_CONFIG_SECTIONS );
619
+ return 0 ;
620
+ case HELP_ACTION_CONFIG :
621
+ no_extra_argc (argc );
622
+ setup_pager ();
623
+ list_config_help (SHOW_CONFIG_HUMAN );
624
+ printf ("\n%s\n" , _ ("'git help config' for more information" ));
590
625
return 0 ;
591
626
}
592
627
0 commit comments