8
#include "parse-options.h"
9
#include "run-command.h"
10
#include "column.h"
11
+#include "config-list.h"
12
#include "help.h"
13
#include "alias.h"
14
63
NULL
64
};
65
66
+struct slot_expansion {
67
+ const char *prefix;
68
+ const char *placeholder;
69
+ void (*fn)(struct string_list *list, const char *prefix);
70
+ int found;
71
+};
72
+
73
+static void list_config_help(int for_human)
74
+{
75
+ struct slot_expansion slot_expansions[] = {
76
+ { "advice", "*", list_config_advices },
77
+ { "color.branch", "<slot>", list_config_color_branch_slots },
78
+ { "color.decorate", "<slot>", list_config_color_decorate_slots },
79
+ { "color.diff", "<slot>", list_config_color_diff_slots },
80
+ { "color.grep", "<slot>", list_config_color_grep_slots },
81
+ { "color.interactive", "<slot>", list_config_color_interactive_slots },
82
+ { "color.remote", "<slot>", list_config_color_sideband_slots },
83
+ { "color.status", "<slot>", list_config_color_status_slots },
84
+ { "fsck", "<msg-id>", list_config_fsck_msg_ids },
85
+ { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
86
+ { NULL, NULL, NULL }
87
+ };
88
+ const char **p;
89
+ struct slot_expansion *e;
90
+ struct string_list keys = STRING_LIST_INIT_DUP;
91
+ int i;
92
+
93
+ for (p = config_name_list; *p; p++) {
94
+ const char *var = *p;
95
+ struct strbuf sb = STRBUF_INIT;
96
+
97
+ for (e = slot_expansions; e->prefix; e++) {
98
+
99
+ strbuf_reset(&sb);
100
+ strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder);
101
+ if (!strcasecmp(var, sb.buf)) {
102
+ e->fn(&keys, e->prefix);
103
+ e->found++;
104
+ break;
105
+ }
106
+ }
107
+ strbuf_release(&sb);
108
+ if (!e->prefix)
109
+ string_list_append(&keys, var);
110
+ }
111
+
112
+ for (e = slot_expansions; e->prefix; e++)
113
+ if (!e->found)
114
+ BUG("slot_expansion %s.%s is not used",
115
+ e->prefix, e->placeholder);
116
+
117
+ string_list_sort(&keys);
118
+ for (i = 0; i < keys.nr; i++) {
119
+ const char *var = keys.items[i].string;
120
+ const char *wildcard, *tag, *cut;
121
+
122
+ if (for_human) {
123
+ puts(var);
124
+ continue;
125
+ }
126
+
127
+ wildcard = strchr(var, '*');
128
+ tag = strchr(var, '<');
129
+
130
+ if (!wildcard && !tag) {
131
+ puts(var);
132
+ continue;
133
+ }
134
+
135
+ if (wildcard && !tag)
136
+ cut = wildcard;
137
+ else if (!wildcard && tag)
138
+ cut = tag;
139
+ else
140
+ cut = wildcard < tag ? wildcard : tag;
141
+
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);
147
+ }
148
+ string_list_clear(&keys, 0);
149
+}
150
+
151
static enum help_format parse_help_format(const char *format)
152
{
153
if (!strcmp(format, "man"))