tag: use OPT_CMDMODE

This is just a demonstration of how the code would look like; I do not think it is particularly easier to read than before myself. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 30, 2013 at 12:31 UTC e6b722db099f435f21ce72b18f0d61dc3c778f1f
1 file changed +12 -15
builtin/tag.c
+12 -15
@@ -436,18 +436,18 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
436 struct ref_lock *lock;
437 struct create_tag_options opt;
438 char *cleanup_arg = NULL;
439 - int annotate = 0, force = 0, lines = -1, list = 0,
440 - delete = 0, verify = 0;
439 + int annotate = 0, force = 0, lines = -1;
440 + int cmdmode = 0;
441 const char *msgfile = NULL, *keyid = NULL;
442 struct msg_arg msg = { 0, STRBUF_INIT };
443 struct commit_list *with_commit = NULL;
444 struct option options[] = {
445 - OPT_BOOLEAN('l', "list", &list, N_("list tag names")),
445 + OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
446 { OPTION_INTEGER, 'n', NULL, &lines, N_("n"),
447 N_("print <n> lines of each tag message"),
448 PARSE_OPT_OPTARG, NULL, 1 },
449 - OPT_BOOLEAN('d', "delete", &delete, N_("delete tags")),
450 - OPT_BOOLEAN('v', "verify", &verify, N_("verify tags")),
449 + OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'),
450 + OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'),
451
452 OPT_GROUP(N_("Tag creation options")),
453 OPT_BOOLEAN('a', "annotate", &annotate,
@@ -489,22 +489,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
489 }
490 if (opt.sign)
491 annotate = 1;
492 - if (argc == 0 && !(delete || verify))
493 - list = 1;
492 + if (argc == 0 && !cmdmode)
493 + cmdmode = 'l';
494
495 - if ((annotate || msg.given || msgfile || force) &&
496 - (list || delete || verify))
495 + if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
496 usage_with_options(git_tag_usage, options);
497
499 - if (list + delete + verify > 1)
500 - usage_with_options(git_tag_usage, options);
498 finalize_colopts(&colopts, -1);
502 - if (list && lines != -1) {
499 + if (cmdmode == 'l' && lines != -1) {
500 if (explicitly_enable_column(colopts))
501 die(_("--column and -n are incompatible"));
502 colopts = 0;
503 }
507 - if (list) {
504 + if (cmdmode == 'l') {
505 int ret;
506 if (column_active(colopts)) {
507 struct column_options copts;
@@ -523,9 +520,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
520 die(_("--contains option is only allowed with -l."));
521 if (points_at.nr)
522 die(_("--points-at option is only allowed with -l."));
526 - if (delete)
523 + if (cmdmode == 'd')
524 return for_each_tag_name(argv, delete_tag);
528 - if (verify)
525 + if (cmdmode == 'v')
526 return for_each_tag_name(argv, verify_tag);
527
528 if (msg.given || msgfile) {