git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] multi-pack-index: simplify handling of unknown --options
@ 2022-07-08 20:28 SZEDER Gábor
  2022-07-08 21:08 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: SZEDER Gábor @ 2022-07-08 20:28 UTC (permalink / raw)
  To: git; +Cc: SZEDER Gábor

Although parse_options() can handle unknown --options just fine, none
of 'git multi-pack-index's subcommands rely on it, but do it on their
own: they invoke parse_options() with the PARSE_OPT_KEEP_UNKNOWN flag,
then check whether there are any unparsed arguments left, and print
usage and quit if necessary.

Let parse_options() handle unknown options instead, which, besides
simpler code, has the additional benefit that it prints not only the
usage but an "error: unknown option `foo'" message as well.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 builtin/multi-pack-index.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 5edbb7fe86..97a87ad8cb 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -134,10 +134,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
 		opts.flags |= MIDX_PROGRESS;
 	argc = parse_options(argc, argv, NULL,
 			     options, builtin_multi_pack_index_write_usage,
-			     PARSE_OPT_KEEP_UNKNOWN);
-	if (argc)
-		usage_with_options(builtin_multi_pack_index_write_usage,
-				   options);
+			     0);
 
 	FREE_AND_NULL(options);
 
@@ -176,10 +173,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv)
 		opts.flags |= MIDX_PROGRESS;
 	argc = parse_options(argc, argv, NULL,
 			     options, builtin_multi_pack_index_verify_usage,
-			     PARSE_OPT_KEEP_UNKNOWN);
-	if (argc)
-		usage_with_options(builtin_multi_pack_index_verify_usage,
-				   options);
+			     0);
 
 	FREE_AND_NULL(options);
 
@@ -202,10 +196,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv)
 		opts.flags |= MIDX_PROGRESS;
 	argc = parse_options(argc, argv, NULL,
 			     options, builtin_multi_pack_index_expire_usage,
-			     PARSE_OPT_KEEP_UNKNOWN);
-	if (argc)
-		usage_with_options(builtin_multi_pack_index_expire_usage,
-				   options);
+			     0);
 
 	FREE_AND_NULL(options);
 
@@ -232,10 +223,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv)
 	argc = parse_options(argc, argv, NULL,
 			     options,
 			     builtin_multi_pack_index_repack_usage,
-			     PARSE_OPT_KEEP_UNKNOWN);
-	if (argc)
-		usage_with_options(builtin_multi_pack_index_repack_usage,
-				   options);
+			     0);
 
 	FREE_AND_NULL(options);
 
-- 
2.37.0.340.g5e8d960d32


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-10 21:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-08 20:28 [PATCH] multi-pack-index: simplify handling of unknown --options SZEDER Gábor
2022-07-08 21:08 ` Junio C Hamano
2022-07-10 15:16   ` SZEDER Gábor
2022-07-10 16:26     ` Ævar Arnfjörð Bjarmason
2022-07-10 21:54     ` Junio C Hamano

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).