From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>,
Pierre Habouzit <madcoder@debian.org>
Cc: git@vger.kernel.org
Subject: [PATCH 3/4] parse-options: add new function "usage_msg_opt"
Date: Mon, 2 Feb 2009 06:12:58 +0100 [thread overview]
Message-ID: <20090202061258.e044e2b7.chriscool@tuxfamily.org> (raw)
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>
---
parse-options.c | 8 ++++++++
parse-options.h | 4 ++++
2 files changed, 12 insertions(+), 0 deletions(-)
This patch may be generaly useful.
diff --git a/parse-options.c b/parse-options.c
index 4c5d09d..7a5fde8 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -449,6 +449,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)
{
diff --git a/parse-options.h b/parse-options.h
index 9122905..6061a19 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -113,6 +113,10 @@ extern int parse_options(int argc, const char **argv,
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);
+
/*----- incremantal advanced APIs -----*/
enum {
--
1.6.1.2.353.g99fdd.dirty
reply other threads:[~2009-02-02 5:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090202061258.e044e2b7.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madcoder@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).