Raw
1 #ifndef PARSE_OPTIONS_H
2 #define PARSE_OPTIONS_H
3
4 #include "gettext.h"
5
6 struct repository;
7
8 /**
9 * Refer to Documentation/technical/api-parse-options.adoc for the API doc.
10 */
11
12 enum parse_opt_type {
13 /* special types */
14 OPTION_END,
15 OPTION_GROUP,
16 OPTION_NUMBER,
17 OPTION_ALIAS,
18 OPTION_SUBCOMMAND,
19 /* options with no arguments */
20 OPTION_BIT,
21 OPTION_NEGBIT,
22 OPTION_BITOP,
23 OPTION_COUNTUP,
24 OPTION_SET_INT,
25 /* options with arguments (usually) */
26 OPTION_STRING,
27 OPTION_INTEGER,
28 OPTION_UNSIGNED,
29 OPTION_CALLBACK,
30 OPTION_LOWLEVEL_CALLBACK,
31 OPTION_FILENAME
32 };
33
34 enum parse_opt_flags {
35 PARSE_OPT_KEEP_DASHDASH = 1 << 0,
36 PARSE_OPT_STOP_AT_NON_OPTION = 1 << 1,
37 PARSE_OPT_KEEP_ARGV0 = 1 << 2,
38 PARSE_OPT_KEEP_UNKNOWN_OPT = 1 << 3,
39 PARSE_OPT_NO_INTERNAL_HELP = 1 << 4,
40 PARSE_OPT_ONE_SHOT = 1 << 5,
41 PARSE_OPT_SHELL_EVAL = 1 << 6,
42 PARSE_OPT_SUBCOMMAND_OPTIONAL = 1 << 7,
43 };
44
45 enum parse_opt_option_flags {
46 PARSE_OPT_OPTARG = 1 << 0,
47 PARSE_OPT_NOARG = 1 << 1,
48 PARSE_OPT_NONEG = 1 << 2,
49 PARSE_OPT_HIDDEN = 1 << 3,
50 PARSE_OPT_LASTARG_DEFAULT = 1 << 4,
51 PARSE_OPT_NODASH = 1 << 5,
52 PARSE_OPT_LITERAL_ARGHELP = 1 << 6,
53 PARSE_OPT_FROM_ALIAS = 1 << 7,
54 PARSE_OPT_NOCOMPLETE = 1 << 9,
55 PARSE_OPT_COMP_ARG = 1 << 10,
56 PARSE_OPT_CMDMODE = 1 << 11,
57 };
58
59 enum parse_opt_result {
60 PARSE_OPT_COMPLETE = -4,
61 PARSE_OPT_HELP_ERROR = -3,
62 PARSE_OPT_HELP = -2,
63 PARSE_OPT_ERROR = -1, /* must be the same as error() */
64 PARSE_OPT_DONE = 0, /* fixed so that "return 0" works */
65 PARSE_OPT_NON_OPTION,
66 PARSE_OPT_SUBCOMMAND,
67 PARSE_OPT_UNKNOWN
68 };
69
70 struct option;
71 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
72
73 struct parse_opt_ctx_t;
74 typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
75 const struct option *opt,
76 const char *arg, int unset);
77
78 typedef int parse_opt_subcommand_fn(int argc, const char **argv,
79 const char *prefix, struct repository *repo);
80
81 /*
82 * `type`::
83 * holds the type of the option, you must have an OPTION_END last in your
84 * array.
85 *
86 * `short_name`::
87 * the character to use as a short option name, '\0' if none.
88 *
89 * `long_name`::
90 * the long option (without the leading dashes) or subcommand name,
91 * NULL if none.
92 *
93 * `value`::
94 * stores pointers to the values to be filled.
95 *
96 * `precision`::
97 * precision of the integer pointed to by `value` in number of bytes. Should
98 * typically be its `sizeof()`.
99 *
100 * `argh`::
101 * token to explain the kind of argument this option wants. Does not
102 * begin in capital letter, and does not end with a full stop.
103 * Should be wrapped by N_() for translation.
104 * Is automatically enclosed in brackets when printed, unless it
105 * contains any of the following characters: ()<>[]|
106 * E.g. "name" is shown as "<name>" to indicate that a name value
107 * needs to be supplied, not the literal string "name", but
108 * "<start>,<end>" and "(this|that)" are printed verbatim.
109 *
110 * `help`::
111 * the short help associated to what the option does.
112 * Must never be NULL (except for OPTION_END and OPTION_SUBCOMMAND).
113 * OPTION_GROUP uses this pointer to store the group header.
114 * Should be wrapped by N_() for translation.
115 *
116 * `flags`::
117 * mask of parse_opt_option_flags.
118 * PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs)
119 * PARSE_OPT_NOARG: says that this option does not take an argument
120 * PARSE_OPT_NONEG: says that this option cannot be negated
121 * (i.e. rejects "--no-<option>")
122 * PARSE_OPT_HIDDEN: this option is skipped in the default usage, and
123 * shown only in the full usage.
124 * PARSE_OPT_LASTARG_DEFAULT: says that this option will take the default
125 * value if no argument is given when the option
126 * is last on the command line. If the option is
127 * not last it will require an argument.
128 * Should not be used with PARSE_OPT_OPTARG.
129 * PARSE_OPT_NODASH: this option doesn't start with a dash; can only be a
130 * short option and can't accept arguments.
131 * PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets
132 * (i.e. '<argh>') in the help message.
133 * Useful for options with multiple parameters.
134 * PARSE_OPT_NOCOMPLETE: by default all visible options are completable
135 * by git-completion.bash. This option suppresses that.
136 * PARSE_OPT_COMP_ARG: this option forces to git-completion.bash to
137 * complete an option as --name= not --name even if
138 * the option takes optional argument.
139 *
140 * `callback`::
141 * pointer to the callback to use for OPTION_CALLBACK
142 *
143 * `defval`::
144 * default value to fill (*->value) with for PARSE_OPT_OPTARG.
145 * OPTION_{BIT,SET_INT} store the {mask,integer} to put in the value when met.
146 * CALLBACKS can use it like they want.
147 *
148 * `ll_callback`::
149 * pointer to the callback to use for OPTION_LOWLEVEL_CALLBACK
150 *
151 * `subcommand_fn`::
152 * pointer to a function to use for OPTION_SUBCOMMAND.
153 * It will be put in value when the subcommand is given on the command line.
154 */
155 struct option {
156 enum parse_opt_type type;
157 int short_name;
158 const char *long_name;
159 void *value;
160 size_t precision;
161 const char *argh;
162 const char *help;
163
164 enum parse_opt_option_flags flags;
165 parse_opt_cb *callback;
166 intptr_t defval;
167 parse_opt_ll_cb *ll_callback;
168 intptr_t extra;
169 parse_opt_subcommand_fn *subcommand_fn;
170 };
171
172 #define OPT_BIT_F(s, l, v, h, b, f) { \
173 .type = OPTION_BIT, \
174 .short_name = (s), \
175 .long_name = (l), \
176 .value = (v), \
177 .precision = sizeof(*v), \
178 .help = (h), \
179 .flags = PARSE_OPT_NOARG|(f), \
180 .callback = NULL, \
181 .defval = (b), \
182 }
183 #define OPT_COUNTUP_F(s, l, v, h, f) { \
184 .type = OPTION_COUNTUP, \
185 .short_name = (s), \
186 .long_name = (l), \
187 .value = (v), \
188 .precision = sizeof(*v), \
189 .help = (h), \
190 .flags = PARSE_OPT_NOARG|(f), \
191 }
192 #define OPT_SET_INT_F(s, l, v, h, i, f) { \
193 .type = OPTION_SET_INT, \
194 .short_name = (s), \
195 .long_name = (l), \
196 .value = (v), \
197 .precision = sizeof(*v), \
198 .help = (h), \
199 .flags = PARSE_OPT_NOARG | (f), \
200 .defval = (i), \
201 }
202 #define OPT_BOOL_F(s, l, v, h, f) OPT_SET_INT_F(s, l, v, h, 1, f)
203 #define OPT_CALLBACK_F(s, l, v, a, h, f, cb) { \
204 .type = OPTION_CALLBACK, \
205 .short_name = (s), \
206 .long_name = (l), \
207 .value = (v), \
208 .argh = (a), \
209 .help = (h), \
210 .flags = (f), \
211 .callback = (cb), \
212 }
213 #define OPT_STRING_F(s, l, v, a, h, f) { \
214 .type = OPTION_STRING, \
215 .short_name = (s), \
216 .long_name = (l), \
217 .value = (v), \
218 .argh = (a), \
219 .help = (h), \
220 .flags = (f), \
221 }
222 #define OPT_INTEGER_F(s, l, v, h, f) { \
223 .type = OPTION_INTEGER, \
224 .short_name = (s), \
225 .long_name = (l), \
226 .value = (v) + BARF_UNLESS_SIGNED(*(v)), \
227 .precision = sizeof(*v), \
228 .argh = N_("n"), \
229 .help = (h), \
230 .flags = (f), \
231 }
232
233 #define OPT_END() { \
234 .type = OPTION_END, \
235 }
236 #define OPT_GROUP(h) { \
237 .type = OPTION_GROUP, \
238 .help = (h), \
239 }
240 #define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
241 #define OPT_BITOP(s, l, v, h, set, clear) { \
242 .type = OPTION_BITOP, \
243 .short_name = (s), \
244 .long_name = (l), \
245 .value = (v), \
246 .precision = sizeof(*v), \
247 .help = (h), \
248 .flags = PARSE_OPT_NOARG|PARSE_OPT_NONEG, \
249 .defval = (set), \
250 .extra = (clear), \
251 }
252 #define OPT_NEGBIT(s, l, v, h, b) { \
253 .type = OPTION_NEGBIT, \
254 .short_name = (s), \
255 .long_name = (l), \
256 .value = (v), \
257 .precision = sizeof(*v), \
258 .help = (h), \
259 .flags = PARSE_OPT_NOARG, \
260 .defval = (b), \
261 }
262 #define OPT_COUNTUP(s, l, v, h) OPT_COUNTUP_F(s, l, v, h, 0)
263 #define OPT_SET_INT(s, l, v, h, i) OPT_SET_INT_F(s, l, v, h, i, 0)
264 #define OPT_BOOL(s, l, v, h) OPT_BOOL_F(s, l, v, h, 0)
265 #define OPT_HIDDEN_BOOL(s, l, v, h) { \
266 .type = OPTION_SET_INT, \
267 .short_name = (s), \
268 .long_name = (l), \
269 .value = (v), \
270 .precision = sizeof(*v), \
271 .help = (h), \
272 .flags = PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, \
273 .defval = 1, \
274 }
275 #define OPT_CMDMODE_F(s, l, v, h, i, f) { \
276 .type = OPTION_SET_INT, \
277 .short_name = (s), \
278 .long_name = (l), \
279 .value = (v), \
280 .precision = sizeof(*v), \
281 .help = (h), \
282 .flags = PARSE_OPT_CMDMODE|PARSE_OPT_NOARG|PARSE_OPT_NONEG | (f), \
283 .defval = (i), \
284 }
285 #define OPT_CMDMODE(s, l, v, h, i) OPT_CMDMODE_F(s, l, v, h, i, 0)
286
287 #define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
288 #define OPT_UNSIGNED(s, l, v, h) { \
289 .type = OPTION_UNSIGNED, \
290 .short_name = (s), \
291 .long_name = (l), \
292 .value = (v) + BARF_UNLESS_UNSIGNED(*(v)), \
293 .precision = sizeof(*v), \
294 .argh = N_("n"), \
295 .help = (h), \
296 .flags = PARSE_OPT_NONEG, \
297 }
298 #define OPT_STRING(s, l, v, a, h) OPT_STRING_F(s, l, v, a, h, 0)
299 #define OPT_STRING_LIST(s, l, v, a, h) { \
300 .type = OPTION_CALLBACK, \
301 .short_name = (s), \
302 .long_name = (l), \
303 .value = (v), \
304 .argh = (a), \
305 .help = (h), \
306 .callback = &parse_opt_string_list, \
307 }
308 #define OPT_STRVEC(s, l, v, a, h) { \
309 .type = OPTION_CALLBACK, \
310 .short_name = (s), \
311 .long_name = (l), \
312 .value = (v), \
313 .argh = (a), \
314 .help = (h), \
315 .callback = &parse_opt_strvec, \
316 }
317 #define OPT_UYN(s, l, v, h) { \
318 .type = OPTION_CALLBACK, \
319 .short_name = (s), \
320 .long_name = (l), \
321 .value = (v), \
322 .help = (h), \
323 .flags = PARSE_OPT_NOARG, \
324 .callback = &parse_opt_tertiary, \
325 }
326 #define OPT_EXPIRY_DATE(s, l, v, h) { \
327 .type = OPTION_CALLBACK, \
328 .short_name = (s), \
329 .long_name = (l), \
330 .value = (v), \
331 .argh = N_("expiry-date"), \
332 .help = (h), \
333 .callback = parse_opt_expiry_date_cb, \
334 }
335 #define OPT_CALLBACK(s, l, v, a, h, cb) OPT_CALLBACK_F(s, l, v, a, h, 0, cb)
336 #define OPT_NUMBER_CALLBACK(v, h, cb) { \
337 .type = OPTION_NUMBER, \
338 .value = (v), \
339 .help = (h), \
340 .flags = PARSE_OPT_NOARG | PARSE_OPT_NONEG, \
341 .callback = (cb), \
342 }
343 #define OPT_FILENAME(s, l, v, h) { \
344 .type = OPTION_FILENAME, \
345 .short_name = (s), \
346 .long_name = (l), \
347 .value = (v), \
348 .argh = N_("file"), \
349 .help = (h), \
350 }
351 #define OPT_COLOR_FLAG(s, l, v, h) { \
352 .type = OPTION_CALLBACK, \
353 .short_name = (s), \
354 .long_name = (l), \
355 .value = (v), \
356 .argh = N_("when"), \
357 .help = (h), \
358 .flags = PARSE_OPT_OPTARG, \
359 .callback = parse_opt_color_flag_cb, \
360 .defval = (intptr_t)"always", \
361 }
362
363 #define OPT_NOOP_NOARG(s, l) { \
364 .type = OPTION_CALLBACK, \
365 .short_name = (s), \
366 .long_name = (l), \
367 .help = N_("no-op (backward compatibility)"), \
368 .flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, \
369 .callback = parse_opt_noop_cb, \
370 }
371
372 static char *parse_options_noop_ignored_value MAYBE_UNUSED;
373 #define OPT_NOOP_ARG(s, l) { \
374 .type = OPTION_CALLBACK, \
375 .short_name = (s), \
376 .long_name = (l), \
377 .value = &parse_options_noop_ignored_value, \
378 .argh = "ignored", \
379 .help = N_("no-op (backward compatibility)"), \
380 .flags = PARSE_OPT_HIDDEN, \
381 .callback = parse_opt_noop_cb, \
382 }
383
384 #define OPT_ALIAS(s, l, source_long_name) { \
385 .type = OPTION_ALIAS, \
386 .short_name = (s), \
387 .long_name = (l), \
388 .value = (char *)(source_long_name), \
389 }
390
391 #define OPT_SUBCOMMAND_F(l, v, fn, f) { \
392 .type = OPTION_SUBCOMMAND, \
393 .long_name = (l), \
394 .value = (v), \
395 .flags = (f), \
396 .subcommand_fn = (fn), \
397 }
398 #define OPT_SUBCOMMAND(l, v, fn) OPT_SUBCOMMAND_F((l), (v), (fn), 0)
399
400 /*
401 * parse_options() will filter out the processed options and leave the
402 * non-option arguments in argv[]. argv0 is assumed program name and
403 * skipped.
404 *
405 * usagestr strings should be marked for translation with N_().
406 *
407 * Returns the number of arguments left in argv[].
408 *
409 * In one-shot mode, argv0 is not a program name, argv[] is left
410 * untouched and parse_options() returns the number of options
411 * processed.
412 */
413 int parse_options(int argc, const char **argv, const char *prefix,
414 const struct option *options,
415 const char * const usagestr[],
416 enum parse_opt_flags flags);
417
418 NORETURN void usage_with_options(const char * const *usagestr,
419 const struct option *options);
420
421 void show_usage_with_options_if_asked(int ac, const char **av,
422 const char * const *usage,
423 const struct option *options);
424
425 NORETURN void usage_msg_opt(const char *msg,
426 const char * const *usagestr,
427 const struct option *options);
428
429 /**
430 * usage_msg_optf() is like usage_msg_opt() except that the first
431 * argument is a format string, and optional format arguments follow
432 * after the 3rd option.
433 */
434 __attribute__((format (printf,1,4)))
435 void NORETURN usage_msg_optf(const char *fmt,
436 const char * const *usagestr,
437 const struct option *options, ...);
438
439 void die_for_incompatible_opt4(int opt1, const char *opt1_name,
440 int opt2, const char *opt2_name,
441 int opt3, const char *opt3_name,
442 int opt4, const char *opt4_name);
443
444
445 static inline void die_for_incompatible_opt3(int opt1, const char *opt1_name,
446 int opt2, const char *opt2_name,
447 int opt3, const char *opt3_name)
448 {
449 die_for_incompatible_opt4(opt1, opt1_name,
450 opt2, opt2_name,
451 opt3, opt3_name,
452 0, "");
453 }
454
455 static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
456 int opt2, const char *opt2_name)
457 {
458 die_for_incompatible_opt4(opt1, opt1_name,
459 opt2, opt2_name,
460 0, "",
461 0, "");
462 }
463
464 /*
465 * Use these assertions for callbacks that expect to be called with NONEG and
466 * NOARG respectively, and do not otherwise handle the "unset" and "arg"
467 * parameters.
468 */
469 #define BUG_ON_OPT_NEG(unset) do { \
470 if ((unset)) \
471 BUG("option callback does not expect negation"); \
472 } while (0)
473 #define BUG_ON_OPT_ARG(arg) do { \
474 if ((arg)) \
475 BUG("option callback does not expect an argument"); \
476 } while (0)
477
478 /*
479 * Similar to the assertions above, but checks that "arg" is always non-NULL.
480 * This assertion also implies BUG_ON_OPT_NEG(), letting you declare both
481 * assertions in a single line.
482 */
483 #define BUG_ON_OPT_NEG_NOARG(unset, arg) do { \
484 BUG_ON_OPT_NEG(unset); \
485 if(!(arg)) \
486 BUG("option callback expects an argument"); \
487 } while(0)
488
489 /*----- incremental advanced APIs -----*/
490
491 struct parse_opt_cmdmode_list;
492
493 /*
494 * It's okay for the caller to consume argv/argc in the usual way.
495 * Other fields of that structure are private to parse-options and should not
496 * be modified in any way.
497 */
498 struct parse_opt_ctx_t {
499 const char **argv;
500 const char **out;
501 int argc, cpidx, total;
502 const char *opt;
503 enum parse_opt_flags flags;
504 unsigned has_subcommands;
505 const char *prefix;
506 const char **alias_groups; /* must be in groups of 3 elements! */
507 struct parse_opt_cmdmode_list *cmdmode_list;
508 };
509
510 void parse_options_start(struct parse_opt_ctx_t *ctx,
511 int argc, const char **argv, const char *prefix,
512 const struct option *options,
513 enum parse_opt_flags flags);
514
515 enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
516 const struct option *options,
517 const char * const usagestr[]);
518
519 int parse_options_end(struct parse_opt_ctx_t *ctx);
520
521 struct option *parse_options_dup(const struct option *a);
522 struct option *parse_options_concat(const struct option *a, const struct option *b);
523
524 /*----- some often used options -----*/
525 int parse_opt_abbrev_cb(const struct option *, const char *, int);
526 int parse_opt_expiry_date_cb(const struct option *, const char *, int);
527 int parse_opt_color_flag_cb(const struct option *, const char *, int);
528 int parse_opt_verbosity_cb(const struct option *, const char *, int);
529 /* value is struct oid_array* */
530 int parse_opt_object_name(const struct option *, const char *, int);
531 /* value is struct object_id* */
532 int parse_opt_object_id(const struct option *, const char *, int);
533 int parse_opt_commits(const struct option *, const char *, int);
534 int parse_opt_commit(const struct option *, const char *, int);
535 int parse_opt_tertiary(const struct option *, const char *, int);
536 int parse_opt_string_list(const struct option *, const char *, int);
537 int parse_opt_strvec(const struct option *, const char *, int);
538 int parse_opt_noop_cb(const struct option *, const char *, int);
539 int parse_opt_passthru(const struct option *, const char *, int);
540 int parse_opt_passthru_argv(const struct option *, const char *, int);
541 /* value is enum branch_track* */
542 int parse_opt_tracking_mode(const struct option *, const char *, int);
543
544 #define OPT__VERBOSE(var, h) OPT_COUNTUP('v', "verbose", (var), (h))
545 #define OPT__QUIET(var, h) OPT_COUNTUP('q', "quiet", (var), (h))
546 #define OPT__VERBOSITY(var) { \
547 .type = OPTION_CALLBACK, \
548 .short_name = 'v', \
549 .long_name = "verbose", \
550 .value = (var), \
551 .help = N_("be more verbose"), \
552 .flags = PARSE_OPT_NOARG, \
553 .callback = &parse_opt_verbosity_cb, \
554 }, { \
555 .type = OPTION_CALLBACK, \
556 .short_name = 'q', \
557 .long_name = "quiet", \
558 .value = (var), \
559 .help = N_("be more quiet"), \
560 .flags = PARSE_OPT_NOARG, \
561 .callback = &parse_opt_verbosity_cb, \
562 }
563 #define OPT__DRY_RUN(var, h) OPT_BOOL('n', "dry-run", (var), (h))
564 #define OPT__FORCE(var, h, f) OPT_COUNTUP_F('f', "force", (var), (h), (f))
565 #define OPT__ABBREV(var) { \
566 .type = OPTION_CALLBACK, \
567 .long_name = "abbrev", \
568 .value = (var), \
569 .argh = N_("n"), \
570 .help = N_("use <n> digits to display object names"), \
571 .flags = PARSE_OPT_OPTARG, \
572 .callback = &parse_opt_abbrev_cb, \
573 }
574 #define OPT__SUPER_PREFIX(var) \
575 OPT_STRING_F(0, "super-prefix", (var), N_("prefix"), \
576 N_("prefixed path to initial superproject"), PARSE_OPT_HIDDEN)
577
578 #define OPT__COLOR(var, h) \
579 OPT_COLOR_FLAG(0, "color", (var), (h))
580 #define OPT_COLUMN(s, l, v, h) { \
581 .type = OPTION_CALLBACK, \
582 .short_name = (s), \
583 .long_name = (l), \
584 .value = (v), \
585 .argh = N_("style"), \
586 .help = (h), \
587 .flags = PARSE_OPT_OPTARG, \
588 .callback = parseopt_column_callback, \
589 }
590 #define OPT_PASSTHRU(s, l, v, a, h, f) { \
591 .type = OPTION_CALLBACK, \
592 .short_name = (s), \
593 .long_name = (l), \
594 .value = (v), \
595 .argh = (a), \
596 .help = (h), \
597 .flags = (f), \
598 .callback = parse_opt_passthru, \
599 }
600 #define OPT_PASSTHRU_ARGV(s, l, v, a, h, f) { \
601 .type = OPTION_CALLBACK, \
602 .short_name = (s), \
603 .long_name = (l), \
604 .value = (v), \
605 .argh = (a), \
606 .help = (h), \
607 .flags = (f), \
608 .callback = parse_opt_passthru_argv, \
609 }
610 #define _OPT_CONTAINS_OR_WITH(l, v, h, f) { \
611 .type = OPTION_CALLBACK, \
612 .long_name = (l), \
613 .value = (v), \
614 .argh = N_("commit"), \
615 .help = (h), \
616 .flags = PARSE_OPT_LASTARG_DEFAULT | (f), \
617 .callback = parse_opt_commits, \
618 .defval = (intptr_t) "HEAD", \
619 }
620 #define OPT_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("contains", v, h, PARSE_OPT_NONEG)
621 #define OPT_NO_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("no-contains", v, h, PARSE_OPT_NONEG)
622 #define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)
623 #define OPT_WITHOUT(v, h) _OPT_CONTAINS_OR_WITH("without", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG)
624 #define OPT_CLEANUP(v) OPT_STRING(0, "cleanup", v, N_("mode"), N_("how to strip spaces and #comments from message"))
625 #define OPT_PATHSPEC_FROM_FILE(v) OPT_FILENAME(0, "pathspec-from-file", v, N_("read pathspec from file"))
626 #define OPT_PATHSPEC_FILE_NUL(v) OPT_BOOL(0, "pathspec-file-nul", v, N_("with --pathspec-from-file, pathspec elements are separated with NUL character"))
627 #define OPT_AUTOSTASH(v) OPT_BOOL(0, "autostash", v, N_("automatically stash/stash pop before and after"))
628 #define OPT_DIFF_UNIFIED(v) OPT_INTEGER_F('U', "unified", v, N_("generate diffs with <n> lines context"), PARSE_OPT_NONEG)
629 #define OPT_DIFF_INTERHUNK_CONTEXT(v) OPT_INTEGER_F(0, "inter-hunk-context", v, N_("show context between diff hunks up to the specified number of lines"), PARSE_OPT_NONEG)
630
631 #define OPT_IPVERSION(v) \
632 OPT_SET_INT_F('4', "ipv4", (v), N_("use IPv4 addresses only"), \
633 TRANSPORT_FAMILY_IPV4, PARSE_OPT_NONEG), \
634 OPT_SET_INT_F('6', "ipv6", (v), N_("use IPv6 addresses only"), \
635 TRANSPORT_FAMILY_IPV6, PARSE_OPT_NONEG)
636
637 #endif