multi-pack-index: simplify handling of unknown --options

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.

Drop that PARSE_OPT_KEEP_UNKNOWN flag to let parse_options() handle
unknown options instead, which has the additional benefit that it
prints not only the usage but an "error: unknown option `foo'" message
as well.

Do leave the unparsed arguments check to catch any unexpected
non-option arguments, though, e.g. 'git multi-pack-index write foo'.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
SZEDER Gábor 2022-07-10 17:16:45 +02:00 коммит произвёл Junio C Hamano
Родитель e4a4b31577
Коммит cc74afb83f
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -134,7 +134,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
opts.flags |= MIDX_PROGRESS; opts.flags |= MIDX_PROGRESS;
argc = parse_options(argc, argv, NULL, argc = parse_options(argc, argv, NULL,
options, builtin_multi_pack_index_write_usage, options, builtin_multi_pack_index_write_usage,
PARSE_OPT_KEEP_UNKNOWN); 0);
if (argc) if (argc)
usage_with_options(builtin_multi_pack_index_write_usage, usage_with_options(builtin_multi_pack_index_write_usage,
options); options);
@ -176,7 +176,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv)
opts.flags |= MIDX_PROGRESS; opts.flags |= MIDX_PROGRESS;
argc = parse_options(argc, argv, NULL, argc = parse_options(argc, argv, NULL,
options, builtin_multi_pack_index_verify_usage, options, builtin_multi_pack_index_verify_usage,
PARSE_OPT_KEEP_UNKNOWN); 0);
if (argc) if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage, usage_with_options(builtin_multi_pack_index_verify_usage,
options); options);
@ -202,7 +202,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv)
opts.flags |= MIDX_PROGRESS; opts.flags |= MIDX_PROGRESS;
argc = parse_options(argc, argv, NULL, argc = parse_options(argc, argv, NULL,
options, builtin_multi_pack_index_expire_usage, options, builtin_multi_pack_index_expire_usage,
PARSE_OPT_KEEP_UNKNOWN); 0);
if (argc) if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage, usage_with_options(builtin_multi_pack_index_expire_usage,
options); options);
@ -232,7 +232,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv)
argc = parse_options(argc, argv, NULL, argc = parse_options(argc, argv, NULL,
options, options,
builtin_multi_pack_index_repack_usage, builtin_multi_pack_index_repack_usage,
PARSE_OPT_KEEP_UNKNOWN); 0);
if (argc) if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage, usage_with_options(builtin_multi_pack_index_repack_usage,
options); options);