Skip to content

Commit 451bb21

Browse files
chriscoolgitster
authored andcommitted
parse-options: add new function "usage_msg_opt"
This function can be used instead of "usage_with_options" when you want to print an error message before the usage string. It may be useful because: if (condition) usage_msg_opt("condition is false", usage, opts); is shorter than: if (condition) { fprintf(stderr, "condition is false\n\n"); usage_with_options(usage, opts); } and may be more consistent. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bebdd27 commit 451bb21

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

builtin-replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
121121
OPT_END()
122122
};
123123

124-
argc = parse_options(argc, argv, options, git_replace_usage, 0);
124+
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
125125

126126
if (list && delete)
127127
usage_with_options(git_replace_usage, options);

parse-options.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ void usage_with_options(const char * const *usagestr,
555555
exit(129);
556556
}
557557

558+
void usage_msg_opt(const char *msg,
559+
const char * const *usagestr,
560+
const struct option *options)
561+
{
562+
fprintf(stderr, "%s\n\n", msg);
563+
usage_with_options(usagestr, options);
564+
}
565+
558566
int parse_options_usage(const char * const *usagestr,
559567
const struct option *opts)
560568
{

parse-options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ extern int parse_options(int argc, const char **argv, const char *prefix,
132132
extern NORETURN void usage_with_options(const char * const *usagestr,
133133
const struct option *options);
134134

135+
extern NORETURN void usage_msg_opt(const char *msg,
136+
const char * const *usagestr,
137+
const struct option *options);
138+
135139
/*----- incremental advanced APIs -----*/
136140

137141
enum {

0 commit comments

Comments
 (0)