Skip to content

Commit 581b108

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 581b108

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

add-interactive.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,20 @@ 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_ln(stdout, help_color, "status - %s",
252+
_("show paths with changes"));
253+
color_fprintf_ln(stdout, help_color, "update - %s",
254+
_("add working tree state to the staged set of changes"));
255+
color_fprintf_ln(stdout, help_color, "revert - %s",
256+
_("revert staged set of changes back to the HEAD version"));
257+
color_fprintf_ln(stdout, help_color, "patch - %s",
258+
_("pick hunks and update selectively"));
259+
color_fprintf_ln(stdout, help_color, "diff - %s",
260+
_("view diff between HEAD and index"));
261+
color_fprintf_ln(stdout, help_color, "add untracked - %s",
262+
_("add contents of untracked files to the staged set of changes"));
263+
}

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)