git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sunshine@sunshineco.com,
	Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v10 2/4] cat-file: make the options mutually exclusive
Date: Sun,  3 May 2015 20:00:00 +0530	[thread overview]
Message-ID: <1430663402-26717-2-git-send-email-karthik.188@gmail.com> (raw)
In-Reply-To: <1430663402-26717-1-git-send-email-karthik.188@gmail.com>

We only parse the options if 2 or 3 arguments are specified.
Update 'struct option options[]' to use OPT_CMDMODE rather than
OPT_SET_INT to allow only one mutually exclusive option and avoid the
need for checking number of arguments. This was written by Junio C Hamano,
tested by me.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 builtin/cat-file.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index df99df4..53b5376 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -362,12 +362,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 
 	const struct option options[] = {
 		OPT_GROUP(N_("<type> can be one of: blob, tree, commit, tag")),
-		OPT_SET_INT('t', NULL, &opt, N_("show object type"), 't'),
-		OPT_SET_INT('s', NULL, &opt, N_("show object size"), 's'),
-		OPT_SET_INT('e', NULL, &opt,
+		OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'),
+		OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'),
+		OPT_CMDMODE('e', NULL, &opt,
 			    N_("exit with zero when there's no error"), 'e'),
-		OPT_SET_INT('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
-		OPT_SET_INT(0, "textconv", &opt,
+		OPT_CMDMODE('p', NULL, &opt, N_("pretty-print object's content"), 'p'),
+		OPT_CMDMODE(0, "textconv", &opt,
 			    N_("for blob objects, run textconv on object's content"), 'c'),
 		{ OPTION_CALLBACK, 0, "batch", &batch, "format",
 			N_("show info and content of objects fed from the standard input"),
@@ -380,9 +380,6 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 
 	git_config(git_cat_file_config, NULL);
 
-	if (argc != 3 && argc != 2)
-		usage_with_options(cat_file_usage, options);
-
 	argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
 
 	if (opt) {
-- 
2.4.0.rc1.250.gfbd73bd

  reply	other threads:[~2015-05-03 14:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-03 14:28 [PATCH v10 0/4] cat-file: add support for "-allow-unknown-type" karthik nayak
2015-05-03 14:29 ` [PATCH v10 1/4] sha1_file: support reading from a loose object of unknown type Karthik Nayak
2015-05-03 14:30   ` Karthik Nayak [this message]
2015-05-03 14:30   ` [PATCH v10 3/4] cat-file: teach cat-file a '--allow-unknown-type' option Karthik Nayak
2015-05-05  1:29     ` Eric Sunshine
2015-05-03 14:30   ` [PATCH v10 4/4] t1006: add tests for git cat-file --allow-unknown-type Karthik Nayak
2015-05-05  1:33     ` Eric Sunshine
2015-05-05  2:23       ` karthik nayak
2015-05-06  4:37         ` Junio C Hamano
2015-05-04 23:34   ` [PATCH v10 1/4] sha1_file: support reading from a loose object of unknown type Eric Sunshine
2015-05-05  2:21     ` karthik nayak
2015-05-04  0:10 ` [PATCH v10 0/4] cat-file: add support for "-allow-unknown-type" Junio C Hamano
2015-05-04  0:14   ` Junio C Hamano
2015-05-04  2:55     ` Eric Sunshine
2015-05-04  3:30       ` Eric Sunshine
2015-05-04 13:31         ` karthik nayak
2015-05-06 13:37         ` karthik nayak
2015-05-06 17:16           ` Junio C Hamano
2015-05-07  3:34             ` Karthik Nayak
2015-05-07 18:35               ` Junio C Hamano
2015-05-04 13:30     ` karthik nayak
2015-05-04 20:57       ` Junio C Hamano

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=1430663402-26717-2-git-send-email-karthik.188@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.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.
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).