use a helper function to generate error messages for mutually exclusive options Inspired by a different patch from jrick ok jrick
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
diff --git a/got/got.c b/got/got.c
index 7bdd9e1..61bddc5 100644
--- a/got/got.c
+++ b/got/got.c
@@ -183,6 +183,12 @@ list_commands(FILE *fp)
fputc('\n', fp);
}
+__dead static void
+option_conflict(char a, char b)
+{
+ errx(1, "-%c and -%c options are mutually exclusive", a, b);
+}
+
int
main(int argc, char *argv[])
{
@@ -1389,18 +1395,18 @@ cmd_clone(int argc, char *argv[])
argv += optind;
if (fetch_all_branches && !TAILQ_EMPTY(&wanted_branches))
- errx(1, "-a and -b options are mutually exclusive");
+ option_conflict('a', 'b');
if (list_refs_only) {
if (!TAILQ_EMPTY(&wanted_branches))
- errx(1, "-l and -b options are mutually exclusive");
+ option_conflict('l', 'b');
if (fetch_all_branches)
- errx(1, "-l and -a options are mutually exclusive");
+ option_conflict('l', 'a');
if (mirror_references)
- errx(1, "-l and -m options are mutually exclusive");
+ option_conflict('l', 'm');
if (verbosity == -1)
- errx(1, "-l and -q options are mutually exclusive");
+ option_conflict('l', 'q');
if (!TAILQ_EMPTY(&wanted_refs))
- errx(1, "-l and -R options are mutually exclusive");
+ option_conflict('l', 'R');
}
uri = argv[0];
@@ -2062,16 +2068,16 @@ cmd_fetch(int argc, char *argv[])
argv += optind;
if (fetch_all_branches && !TAILQ_EMPTY(&wanted_branches))
- errx(1, "-a and -b options are mutually exclusive");
+ option_conflict('a', 'b');
if (list_refs_only) {
if (!TAILQ_EMPTY(&wanted_branches))
- errx(1, "-l and -b options are mutually exclusive");
+ option_conflict('l', 'b');
if (fetch_all_branches)
- errx(1, "-l and -a options are mutually exclusive");
+ option_conflict('l', 'a');
if (delete_refs)
- errx(1, "-l and -d options are mutually exclusive");
+ option_conflict('l', 'd');
if (verbosity == -1)
- errx(1, "-l and -q options are mutually exclusive");
+ option_conflict('l', 'q');
}
if (argc == 0)
@@ -5195,17 +5201,17 @@ cmd_ref(int argc, char *argv[])
}
if (obj_arg && do_list)
- errx(1, "-c and -l options are mutually exclusive");
+ option_conflict('c', 'l');
if (obj_arg && do_delete)
- errx(1, "-c and -d options are mutually exclusive");
+ option_conflict('c', 'd');
if (obj_arg && symref_target)
- errx(1, "-c and -s options are mutually exclusive");
+ option_conflict('c', 's');
if (symref_target && do_delete)
- errx(1, "-s and -d options are mutually exclusive");
+ option_conflict('s', 'd');
if (symref_target && do_list)
- errx(1, "-s and -l options are mutually exclusive");
+ option_conflict('s', 'l');
if (do_delete && do_list)
- errx(1, "-d and -l options are mutually exclusive");
+ option_conflict('d', 'l');
argc -= optind;
argv += optind;
@@ -5531,7 +5537,7 @@ cmd_branch(int argc, char *argv[])
}
if (do_list && delref)
- errx(1, "-l and -d options are mutually exclusive");
+ option_conflict('l', 'd');
argc -= optind;
argv += optind;
@@ -6067,7 +6073,7 @@ cmd_tag(int argc, char *argv[])
errx(1,
"-c option can only be used when creating a tag");
if (tagmsg)
- errx(1, "-l and -m options are mutually exclusive");
+ option_conflict('l', 'm');
if (argc > 0)
usage_tag();
} else if (argc != 1)
@@ -8624,19 +8630,19 @@ cmd_histedit(int argc, char *argv[])
err(1, "pledge");
#endif
if (abort_edit && continue_edit)
- errx(1, "histedit's -a and -c options are mutually exclusive");
+ option_conflict('a', 'c');
if (edit_script_path && edit_logmsg_only)
- errx(1, "histedit's -F and -m options are mutually exclusive");
+ option_conflict('F', 'm');
if (abort_edit && edit_logmsg_only)
- errx(1, "histedit's -a and -m options are mutually exclusive");
+ option_conflict('a', 'm');
if (continue_edit && edit_logmsg_only)
- errx(1, "histedit's -c and -m options are mutually exclusive");
+ option_conflict('c', 'm');
if (abort_edit && fold_only)
- errx(1, "histedit's -a and -f options are mutually exclusive");
+ option_conflict('a', 'f');
if (continue_edit && fold_only)
- errx(1, "histedit's -c and -f options are mutually exclusive");
+ option_conflict('c', 'f');
if (fold_only && edit_logmsg_only)
- errx(1, "histedit's -f and -m options are mutually exclusive");
+ option_conflict('f', 'm');
if (argc != 0)
usage_histedit();