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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Feb 2, 2009 at 06:12 UTC
451bb210f81c10b60bf90403c9183be26beaaabf
3 files changed
+13
-1
builtin-replace.c
+1
-1
@@ -121,7 +121,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
121
OPT_END()
122
};
123
124
- argc = parse_options(argc, argv, options, git_replace_usage, 0);
124
+ argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
125
126
if (list && delete)
127
usage_with_options(git_replace_usage, options);
parse-options.c
+8
@@ -555,6 +555,14 @@ void usage_with_options(const char * const *usagestr,
555
exit(129);
556
}
557
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
+
566
int parse_options_usage(const char * const *usagestr,
567
const struct option *opts)
568
{
parse-options.h
+4
@@ -132,6 +132,10 @@ extern int parse_options(int argc, const char **argv, const char *prefix,
132
extern NORETURN void usage_with_options(const char * const *usagestr,
133
const struct option *options);
134
135
+extern NORETURN void usage_msg_opt(const char *msg,
136
+ const char * const *usagestr,
137
+ const struct option *options);
138
+
139
/*----- incremental advanced APIs -----*/
140
141
enum {