Skip to content

Commit

Permalink
parse-options: add new function "usage_msg_opt"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chriscool authored and gitster committed Jun 1, 2009
1 parent bebdd27 commit 451bb21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin-replace.c
Expand Up @@ -121,7 +121,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
OPT_END()
};

argc = parse_options(argc, argv, options, git_replace_usage, 0);
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);

if (list && delete)
usage_with_options(git_replace_usage, options);
Expand Down
8 changes: 8 additions & 0 deletions parse-options.c
Expand Up @@ -555,6 +555,14 @@ void usage_with_options(const char * const *usagestr,
exit(129);
}

void usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options)
{
fprintf(stderr, "%s\n\n", msg);
usage_with_options(usagestr, options);
}

int parse_options_usage(const char * const *usagestr,
const struct option *opts)
{
Expand Down
4 changes: 4 additions & 0 deletions parse-options.h
Expand Up @@ -132,6 +132,10 @@ extern int parse_options(int argc, const char **argv, const char *prefix,
extern NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);

extern NORETURN void usage_msg_opt(const char *msg,
const char * const *usagestr,
const struct option *options);

/*----- incremental advanced APIs -----*/

enum {
Expand Down

0 comments on commit 451bb21

Please sign in to comment.