From: "Martin Ågren" <martin.agren@gmail.com>
To: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [GSoC][PATCH v4] Make options that expect object ids less chatty if id is invalid
Date: Thu, 8 Mar 2018 20:27:01 +0100 [thread overview]
Message-ID: <CAN0heSrnERYggyJ8bL1nAV=X2JQYS8aOkc6nWZhnZu3oqhzAfA@mail.gmail.com> (raw)
In-Reply-To: <20180306193116.23876-1-ungureanupaulsebastian@gmail.com>
Hi Paul-Sebastian
On 6 March 2018 at 20:31, Paul-Sebastian Ungureanu
<ungureanupaulsebastian@gmail.com> wrote:
> Usually, the usage should be shown only if the user does not know what
> options are available. If the user specifies an invalid value, the user
> is already aware of the available options. In this case, there is no
> point in displaying the usage anymore.
>
> This patch applies to "git tag --contains", "git branch --contains",
> "git branch --points-at", "git for-each-ref --contains" and many more.
Thanks for scratching this itch.
> 8 files changed, 110 insertions(+), 14 deletions(-)
> create mode 100755 t/tcontains.sh
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 9dcb367b9..a5fbec8fb 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -728,6 +728,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
> PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
> for (;;) {
> switch (parse_options_step(&ctx, options, blame_opt_usage)) {
> + case PARSE_OPT_ERROR:
> case PARSE_OPT_HELP:
> exit(129);
> case PARSE_OPT_DONE:
> diff --git a/builtin/shortlog.c b/builtin/shortlog.c
> index e29875b84..0789e2eea 100644
> --- a/builtin/shortlog.c
> +++ b/builtin/shortlog.c
> @@ -282,6 +282,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
>
> for (;;) {
> switch (parse_options_step(&ctx, options, shortlog_usage)) {
> + case PARSE_OPT_ERROR:
> case PARSE_OPT_HELP:
> exit(129);
> case PARSE_OPT_DONE:
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index 58d1c2d28..34adf55a7 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -1059,6 +1059,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
> break;
> switch (parseopt_state) {
> case PARSE_OPT_HELP:
> + case PARSE_OPT_ERROR:
> exit(129);
> case PARSE_OPT_NON_OPTION:
> case PARSE_OPT_DONE:
> diff --git a/parse-options.c b/parse-options.c
> index d02eb8b01..47c09a82b 100644
> --- a/parse-options.c
> +++ b/parse-options.c
[...]
> int parse_options_end(struct parse_opt_ctx_t *ctx)
> @@ -539,6 +540,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
> parse_options_start(&ctx, argc, argv, prefix, options, flags);
> switch (parse_options_step(&ctx, options, usagestr)) {
> case PARSE_OPT_HELP:
> + case PARSE_OPT_ERROR:
> exit(129);
> case PARSE_OPT_NON_OPTION:
> case PARSE_OPT_DONE:
These are very slightly inconsistent with the ordering of
PARSE_OPT_ERROR and PARSE_OPT_HELP. I don't think it matters much. ;-)
> diff --git a/t/tcontains.sh b/t/tcontains.sh
> new file mode 100755
> index 000000000..4856111ff
> --- /dev/null
> +++ b/t/tcontains.sh
This filename is not on the usual form, t1234-foo. As a result, it it is
not picked up by `make test`, so isn't actually exercised. I believe you
selected this name based on the feedback in [1], but I do not think that
this ("tcontains.sh") was what Junio had in mind. Running the script
manually succeeds though. :-)
> @@ -0,0 +1,92 @@
> +#!/bin/sh
> +
> +test_description='Test "contains" argument behavior'
Ok, that matches the file name.
> +test_expect_success 'setup ' '
> + git init . &&
> + echo "this is a test" >file &&
> + git add -A &&
> + git commit -am "tag test" &&
> + git tag "v1.0" &&
> + git tag "v1.1"
> +'
You might find `test_commit` helpful. All in all, this could be a
two-liner (this example is white-space mangled though):
test_expect_success 'setup ' '
test_commit "v1.0" &&
git tag "v1.1"
'
> +test_expect_success 'tag usage error' '
> + test_must_fail git tag --noopt 2>actual &&
> + test_i18ngrep "usage" actual
> +'
Hmm, this one and a couple like it do not match the filename or test
description. I wonder if these are needed at all, or if some checks like
these are already done elsewhere (maybe not for "git tag", but for some
other user of the option-parsing machinery).
I hope you find this useful.
Martin
[1] https://public-inbox.org/git/xmqqinar1bq2.fsf@gitster-ct.c.googlers.com/
next prev parent reply other threads:[~2018-03-08 19:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 19:31 [GSoC][PATCH v4] Make options that expect object ids less chatty if id is invalid Paul-Sebastian Ungureanu
2018-03-06 21:16 ` Junio C Hamano
2018-03-06 21:28 ` Junio C Hamano
2018-03-08 19:27 ` Martin Ågren [this message]
2018-03-19 18:50 ` ungureanupaulsebastian
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAN0heSrnERYggyJ8bL1nAV=X2JQYS8aOkc6nWZhnZu3oqhzAfA@mail.gmail.com' \
--to=martin.agren@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ungureanupaulsebastian@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).