From: Chirayu Desai <chirayudesai1@gmail.com>
To: git@vger.kernel.org, peff@peff.net
Cc: Chirayu Desai <chirayudesai1@gmail.com>
Subject: [PATCH/GSoC] parse-options: Add a new nousage opt
Date: Sun, 20 Mar 2016 12:16:45 +0530 [thread overview]
Message-ID: <1458456405-3519-1-git-send-email-chirayudesai1@gmail.com> (raw)
* To show only error text on an error instead of the full usage
* Currently used only by commands with options "--with" or "--contains",
such as 'tag', 'branch', 'for-each-ref'.
It now prints only
$ git tag --contains qq
error: malformed object name qq
instead of the full usage text after the error text.
TODO: Add tests
---
parse-options-cb.c | 12 ++++++++----
parse-options.c | 5 +++++
parse-options.h | 6 ++++--
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 239898d946..ac2ea4d674 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -85,11 +85,15 @@ int parse_opt_commits(const struct option *opt, const char *arg, int unset)
if (!arg)
return -1;
- if (get_sha1(arg, sha1))
- return error("malformed object name %s", arg);
+ if (get_sha1(arg, sha1)) {
+ error("malformed object name %s", arg);
+ return -3;
+ }
commit = lookup_commit_reference(sha1);
- if (!commit)
- return error("no such commit %s", arg);
+ if (!commit) {
+ error("no such commit %s", arg);
+ return -3;
+ }
commit_list_insert(commit, opt->value);
return 0;
}
diff --git a/parse-options.c b/parse-options.c
index 47a9192060..d136c1afd0 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -158,6 +158,9 @@ static int get_value(struct parse_opt_ctx_t *p,
return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
if (get_arg(p, opt, flags, &arg))
return -1;
+ if (opt->flags & PARSE_OPT_NOUSAGE) {
+ return (*opt->callback)(opt, arg, 0);
+ }
return (*opt->callback)(opt, arg, 0) ? (-1) : 0;
case OPTION_INTEGER:
@@ -504,6 +507,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
goto show_usage_error;
case -2:
goto unknown;
+ case -3:
+ return PARSE_OPT_DONE;
}
continue;
unknown:
diff --git a/parse-options.h b/parse-options.h
index ea4af92a51..628e34c5af 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -38,7 +38,8 @@ enum parse_opt_option_flags {
PARSE_OPT_LASTARG_DEFAULT = 16,
PARSE_OPT_NODASH = 32,
PARSE_OPT_LITERAL_ARGHELP = 64,
- PARSE_OPT_SHELL_EVAL = 256
+ PARSE_OPT_SHELL_EVAL = 256,
+ PARSE_OPT_NOUSAGE = 512
};
struct option;
@@ -89,6 +90,7 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
* PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets
* (i.e. '<argh>') in the help message.
* Useful for options with multiple parameters.
+ * PARSE_OPT_NOUSAGE: do not print usage / help on error.
*
* `callback`::
* pointer to the callback to use for OPTION_CALLBACK or
@@ -254,7 +256,7 @@ extern int parse_opt_passthru_argv(const struct option *, const char *, int);
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), (f), parse_opt_passthru_argv }
#define _OPT_CONTAINS_OR_WITH(name, variable, help, flag) \
{ OPTION_CALLBACK, 0, name, (variable), N_("commit"), (help), \
- PARSE_OPT_LASTARG_DEFAULT | flag, \
+ PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NOUSAGE | flag, \
parse_opt_commits, (intptr_t) "HEAD" \
}
#define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, 0)
--
2.7.4
next reply other threads:[~2016-03-20 6:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-20 6:46 Chirayu Desai [this message]
2016-03-20 6:52 ` [PATCH/GSoC] parse-options: Add a new nousage opt Chirayu Desai
2016-03-23 22:31 ` Jeff King
2016-03-24 17:21 ` Chirayu Desai
2016-03-24 17:34 ` Jeff King
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=1458456405-3519-1-git-send-email-chirayudesai1@gmail.com \
--to=chirayudesai1@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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).