Skip to content

Commit cf4e913

Browse files
committed
add-interactive.c: implement show-help command
Implement show-help command in add-interactive.c and use it in builtin add--helper.c. Use command name "show-help" instead of "help": add--helper is builtin, hence add--helper --help would be intercepted by handle_builtin and re-routed to the help command, without ever calling cmd_add__helper(). Signed-off-by: Slavica Djukic <[email protected]>
1 parent 4950c88 commit cf4e913

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

add-interactive.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,26 @@ void add_i_print_modified(void)
244244
free(files);
245245
hashmap_free(&s.file_map, 1);
246246
}
247+
248+
void add_i_show_help(void)
249+
{
250+
const char *help_color = get_color(COLOR_HELP);
251+
color_fprintf(stdout, help_color, "%s%s", _("status"),
252+
N_(" - show paths with changes"));
253+
printf("\n");
254+
color_fprintf(stdout, help_color, "%s%s", _("update"),
255+
N_(" - add working tree state to the staged set of changes"));
256+
printf("\n");
257+
color_fprintf(stdout, help_color, "%s%s", _("revert"),
258+
N_(" - revert staged set of changes back to the HEAD version"));
259+
printf("\n");
260+
color_fprintf(stdout, help_color, "%s%s", _("patch"),
261+
N_(" - pick hunks and update selectively"));
262+
printf("\n");
263+
color_fprintf(stdout, help_color, "%s%s", _("diff"),
264+
N_(" - view diff between HEAD and index"));
265+
printf("\n");
266+
color_fprintf(stdout, help_color, "%s%s", _("add untracked"),
267+
N_(" - add contents of untracked files to the staged set of changes"));
268+
printf("\n");
269+
}

add-interactive.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ int add_i_config(const char *var, const char *value, void *cbdata);
55

66
void add_i_print_modified(void);
77

8-
#endif
8+
void add_i_show_help(void);
9+
10+
#endif

builtin/add--helper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ static const char * const builtin_add_helper_usage[] = {
1010

1111
enum cmd_mode {
1212
DEFAULT = 0,
13-
STATUS
13+
STATUS,
14+
HELP
1415
};
1516

1617
int cmd_add__helper(int argc, const char **argv, const char *prefix)
@@ -20,6 +21,8 @@ int cmd_add__helper(int argc, const char **argv, const char *prefix)
2021
struct option options[] = {
2122
OPT_CMDMODE(0, "status", &mode,
2223
N_("print status information with diffstat"), STATUS),
24+
OPT_CMDMODE(0, "show-help", &mode,
25+
N_("show help"), HELP),
2326
OPT_END()
2427
};
2528

@@ -30,6 +33,8 @@ int cmd_add__helper(int argc, const char **argv, const char *prefix)
3033

3134
if (mode == STATUS)
3235
add_i_print_modified();
36+
else if (mode == HELP)
37+
add_i_show_help();
3338
else
3439
usage_with_options(builtin_add_helper_usage,
3540
options);

0 commit comments

Comments
 (0)