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>maint
parent
1158826394
commit
e6b722db09
|
@ -436,18 +436,18 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
struct ref_lock *lock;
|
struct ref_lock *lock;
|
||||||
struct create_tag_options opt;
|
struct create_tag_options opt;
|
||||||
char *cleanup_arg = NULL;
|
char *cleanup_arg = NULL;
|
||||||
int annotate = 0, force = 0, lines = -1, list = 0,
|
int annotate = 0, force = 0, lines = -1;
|
||||||
delete = 0, verify = 0;
|
int cmdmode = 0;
|
||||||
const char *msgfile = NULL, *keyid = NULL;
|
const char *msgfile = NULL, *keyid = NULL;
|
||||||
struct msg_arg msg = { 0, STRBUF_INIT };
|
struct msg_arg msg = { 0, STRBUF_INIT };
|
||||||
struct commit_list *with_commit = NULL;
|
struct commit_list *with_commit = NULL;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_BOOLEAN('l', "list", &list, N_("list tag names")),
|
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
|
||||||
{ OPTION_INTEGER, 'n', NULL, &lines, N_("n"),
|
{ OPTION_INTEGER, 'n', NULL, &lines, N_("n"),
|
||||||
N_("print <n> lines of each tag message"),
|
N_("print <n> lines of each tag message"),
|
||||||
PARSE_OPT_OPTARG, NULL, 1 },
|
PARSE_OPT_OPTARG, NULL, 1 },
|
||||||
OPT_BOOLEAN('d', "delete", &delete, N_("delete tags")),
|
OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'),
|
||||||
OPT_BOOLEAN('v', "verify", &verify, N_("verify tags")),
|
OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'),
|
||||||
|
|
||||||
OPT_GROUP(N_("Tag creation options")),
|
OPT_GROUP(N_("Tag creation options")),
|
||||||
OPT_BOOLEAN('a', "annotate", &annotate,
|
OPT_BOOLEAN('a', "annotate", &annotate,
|
||||||
|
@ -489,22 +489,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
if (opt.sign)
|
if (opt.sign)
|
||||||
annotate = 1;
|
annotate = 1;
|
||||||
if (argc == 0 && !(delete || verify))
|
if (argc == 0 && !cmdmode)
|
||||||
list = 1;
|
cmdmode = 'l';
|
||||||
|
|
||||||
if ((annotate || msg.given || msgfile || force) &&
|
if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
|
||||||
(list || delete || verify))
|
|
||||||
usage_with_options(git_tag_usage, options);
|
usage_with_options(git_tag_usage, options);
|
||||||
|
|
||||||
if (list + delete + verify > 1)
|
|
||||||
usage_with_options(git_tag_usage, options);
|
|
||||||
finalize_colopts(&colopts, -1);
|
finalize_colopts(&colopts, -1);
|
||||||
if (list && lines != -1) {
|
if (cmdmode == 'l' && lines != -1) {
|
||||||
if (explicitly_enable_column(colopts))
|
if (explicitly_enable_column(colopts))
|
||||||
die(_("--column and -n are incompatible"));
|
die(_("--column and -n are incompatible"));
|
||||||
colopts = 0;
|
colopts = 0;
|
||||||
}
|
}
|
||||||
if (list) {
|
if (cmdmode == 'l') {
|
||||||
int ret;
|
int ret;
|
||||||
if (column_active(colopts)) {
|
if (column_active(colopts)) {
|
||||||
struct column_options copts;
|
struct column_options copts;
|
||||||
|
@ -523,9 +520,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
die(_("--contains option is only allowed with -l."));
|
die(_("--contains option is only allowed with -l."));
|
||||||
if (points_at.nr)
|
if (points_at.nr)
|
||||||
die(_("--points-at option is only allowed with -l."));
|
die(_("--points-at option is only allowed with -l."));
|
||||||
if (delete)
|
if (cmdmode == 'd')
|
||||||
return for_each_tag_name(argv, delete_tag);
|
return for_each_tag_name(argv, delete_tag);
|
||||||
if (verify)
|
if (cmdmode == 'v')
|
||||||
return for_each_tag_name(argv, verify_tag);
|
return for_each_tag_name(argv, verify_tag);
|
||||||
|
|
||||||
if (msg.given || msgfile) {
|
if (msg.given || msgfile) {
|
||||||
|
|
Loading…
Reference in New Issue