blob: baced8c1ae6c7994dda4e0a9dd7603270a615092 [file] [log] [blame]
Junio C Hamano3dac5042007-12-15 08:40:541<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamano4604fe52008-09-19 06:37:106<meta name="generator" content="AsciiDoc 8.2.5" />
Junio C Hamano3dac5042007-12-15 08:40:547<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
Junio C Hamano4604fe52008-09-19 06:37:1019a {
20 color: blue;
21 text-decoration: underline;
22}
23a:visited {
24 color: fuchsia;
25}
Junio C Hamano3dac5042007-12-15 08:40:5426
27em {
28 font-style: italic;
29}
30
31strong {
32 font-weight: bold;
33}
34
35tt {
36 color: navy;
37}
38
39h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
45}
46
Junio C Hamano4604fe52008-09-19 06:37:1047h1, h2, h3 {
Junio C Hamano3dac5042007-12-15 08:40:5448 border-bottom: 2px solid silver;
49}
50h2 {
Junio C Hamano3dac5042007-12-15 08:40:5451 padding-top: 0.5em;
52}
Junio C Hamano4604fe52008-09-19 06:37:1053h3 {
54 float: left;
55}
56h3 + * {
57 clear: left;
58}
Junio C Hamano3dac5042007-12-15 08:40:5459
60div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
63}
64
65hr {
66 border: 1px solid silver;
67}
68
69p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
72}
73
74pre {
75 padding: 0;
76 margin: 0;
77}
78
79span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
Junio C Hamano4604fe52008-09-19 06:37:1083 font-size: 1.1em;
Junio C Hamano3dac5042007-12-15 08:40:5484}
85span#email {
86}
87span#revision {
88 font-family: sans-serif;
89}
90
91div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
97}
98div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
101}
102div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
105}
106
107div#preamble,
108div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
114}
115div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
118}
119
120div.content { /* Block element content. */
121 padding: 0;
122}
123
124/* Block element titles. */
125div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
131}
132div.title + * {
133 margin-top: 0;
134}
135
136td div.title:first-child {
137 margin-top: 0.0em;
138}
139div.content div.title:first-child {
140 margin-top: 0.0em;
141}
142div.content + div.title {
143 margin-top: 0.0em;
144}
145
146div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
150}
151
Junio C Hamano4604fe52008-09-19 06:37:10152div.listingblock {
153 margin-right: 0%;
154}
Junio C Hamano3dac5042007-12-15 08:40:54155div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
159}
160
161div.quoteblock > div.content {
162 padding-left: 2.0em;
163}
Junio C Hamano4604fe52008-09-19 06:37:10164
165div.attribution {
Junio C Hamano3dac5042007-12-15 08:40:54166 text-align: right;
167}
Junio C Hamano4604fe52008-09-19 06:37:10168div.verseblock + div.attribution {
169 text-align: left;
170}
Junio C Hamano3dac5042007-12-15 08:40:54171
172div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
179}
180div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
183}
184
185div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
188}
189
190div.verseblock div.content {
191 white-space: pre;
192}
193
194div.imageblock div.content { padding-left: 0; }
195div.imageblock img { border: 1px solid silver; }
196span.image img { border-style: none; }
197
198dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
201}
202dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
206}
207dd > *:first-child {
208 margin-top: 0;
209}
210
211ul, ol {
212 list-style-position: outside;
213}
Junio C Hamano4604fe52008-09-19 06:37:10214div.olist2 ol {
Junio C Hamano3dac5042007-12-15 08:40:54215 list-style-type: lower-alpha;
216}
217
218div.tableblock > table {
Junio C Hamano4604fe52008-09-19 06:37:10219 border: 3px solid #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54220}
221thead {
222 font-family: sans-serif;
223 font-weight: bold;
224}
225tfoot {
226 font-weight: bold;
227}
228
229div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
232}
Junio C Hamano4604fe52008-09-19 06:37:10233div.hlist td {
234 padding-bottom: 5px;
235}
Junio C Hamano3dac5042007-12-15 08:40:54236td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
240}
241td.hlist2 {
242 vertical-align: top;
243}
244
245@media print {
246 div#footer-badges { display: none; }
247}
Junio C Hamano4604fe52008-09-19 06:37:10248
249div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
256}
257
258div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
261}
262div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
265}
266div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
269}
270div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
273}
Junio C Hamano3dac5042007-12-15 08:40:54274/* Workarounds for IE6's broken and incomplete CSS2. */
275
276div.sidebar-content {
277 background: #ffffee;
278 border: 1px solid silver;
279 padding: 0.5em;
280}
281div.sidebar-title, div.image-title {
282 font-family: sans-serif;
283 font-weight: bold;
284 margin-top: 0.0em;
285 margin-bottom: 0.5em;
286}
287
288div.listingblock div.content {
289 border: 1px solid silver;
290 background: #f4f4f4;
291 padding: 0.5em;
292}
293
294div.quoteblock-content {
295 padding-left: 2.0em;
296}
297
298div.exampleblock-content {
299 border-left: 2px solid silver;
300 padding-left: 0.5em;
301}
Junio C Hamano4604fe52008-09-19 06:37:10302
303/* IE6 sets dynamically generated links as visited. */
304div#toc a:visited { color: blue; }
Junio C Hamano3dac5042007-12-15 08:40:54305</style>
306<title>parse-options API</title>
307</head>
308<body>
309<div id="header">
310<h1>parse-options API</h1>
311</div>
312<div id="preamble">
313<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10314<div class="para"><p>The parse-options API is used to parse and massage options in git
315and to provide a usage help with consistent look.</p></div>
Junio C Hamano3dac5042007-12-15 08:40:54316</div>
317</div>
Junio C Hamano4604fe52008-09-19 06:37:10318<h2 id="_basics">Basics</h2>
Junio C Hamano4224f992008-06-23 07:14:08319<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10320<div class="para"><p>The argument vector <tt>argv[]</tt> may usually contain mandatory or optional
Junio C Hamano4224f992008-06-23 07:14:08321<em>non-option arguments</em>, e.g. a filename or a branch, and <em>options</em>.
322Options are optional arguments that start with a dash and
Junio C Hamano4604fe52008-09-19 06:37:10323that allow to change the behavior of a command.</p></div>
324<div class="ilist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08325<li>
326<p>
327There are basically three types of options:
328 <em>boolean</em> options,
329 options with (mandatory) <em>arguments</em> and
330 options with <em>optional arguments</em>
331 (i.e. a boolean option that can be adjusted).
332</p>
333</li>
334<li>
335<p>
336There are basically two forms of options:
337 <em>Short options</em> consist of one dash (<tt>-</tt>) and one alphanumeric
338 character.
339 <em>Long options</em> begin with two dashes (<tt>--</tt>) and some
340 alphanumeric characters.
341</p>
342</li>
343<li>
344<p>
345Options are case-sensitive.
346 Please define <em>lower-case long options</em> only.
347</p>
348</li>
Junio C Hamano4604fe52008-09-19 06:37:10349</ul></div>
350<div class="para"><p>The parse-options API allows:</p></div>
351<div class="ilist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08352<li>
353<p>
354<em>sticked</em> and <em>separate form</em> of options with arguments.
355 <tt>-oArg</tt> is sticked, <tt>-o Arg</tt> is separate form.
356 <tt>--option=Arg</tt> is sticked, <tt>--option Arg</tt> is separate form.
357</p>
358</li>
359<li>
360<p>
361Long options may be <em>abbreviated</em>, as long as the abbreviation
362 is unambiguous.
363</p>
364</li>
365<li>
366<p>
367Short options may be bundled, e.g. <tt>-a -b</tt> can be specified as <tt>-ab</tt>.
368</p>
369</li>
370<li>
371<p>
372Boolean long options can be <em>negated</em> (or <em>unset</em>) by prepending
373 <tt>no-</tt>, e.g. <tt>--no-abbrev</tt> instead of <tt>--abbrev</tt>.
374</p>
375</li>
376<li>
377<p>
378Options and non-option arguments can clearly be separated using the <tt>--</tt>
379 option, e.g. <tt>-a -b --option -- --this-is-a-file</tt> indicates that
380 <tt>--this-is-a-file</tt> must not be processed as an option.
381</p>
382</li>
Junio C Hamano4604fe52008-09-19 06:37:10383</ul></div>
Junio C Hamano4224f992008-06-23 07:14:08384</div>
Junio C Hamano4604fe52008-09-19 06:37:10385<h2 id="_steps_to_parse_options">Steps to parse options</h2>
Junio C Hamano4224f992008-06-23 07:14:08386<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10387<div class="olist"><ol>
Junio C Hamano4224f992008-06-23 07:14:08388<li>
389<p>
390<tt>#include "parse-options.h"</tt>
391</p>
392</li>
393<li>
394<p>
395define a NULL-terminated
396 <tt>static const char * const builtin_foo_usage[]</tt> array
397 containing alternative usage strings
398</p>
399</li>
400<li>
401<p>
402define <tt>builtin_foo_options</tt> array as described below
403 in section <em>Data Structure</em>.
404</p>
405</li>
406<li>
407<p>
408in <tt>cmd_foo(int argc, const char **argv, const char *prefix)</tt>
409 call
410</p>
411<div class="literalblock">
412<div class="content">
Junio C Hamano3d141512009-06-01 01:22:40413<pre><tt>argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags);</tt></pre>
Junio C Hamano4224f992008-06-23 07:14:08414</div></div>
Junio C Hamano4604fe52008-09-19 06:37:10415<div class="para"><p><tt>parse_options()</tt> will filter out the processed options of <tt>argv[]</tt> and leave the
Junio C Hamano4224f992008-06-23 07:14:08416non-option arguments in <tt>argv[]</tt>.
Junio C Hamano4604fe52008-09-19 06:37:10417<tt>argc</tt> is updated appropriately because of the assignment.</p></div>
Junio C Hamano3d141512009-06-01 01:22:40418<div class="para"><p>You can also pass NULL instead of a usage array as the fifth parameter of
Junio C Hamano18f51402009-03-10 16:39:13419parse_options(), to avoid displaying a help screen with usage info and
420option list. This should only be done if necessary, e.g. to implement
421a limited parser for only a subset of the options that needs to be run
422before the full parser, which in turn shows the full help message.</p></div>
Junio C Hamano4604fe52008-09-19 06:37:10423<div class="para"><p>Flags are the bitwise-or of:</p></div>
424<div class="vlist"><dl>
Junio C Hamano4224f992008-06-23 07:14:08425<dt>
426<tt>PARSE_OPT_KEEP_DASHDASH</tt>
427</dt>
428<dd>
429<p>
430 Keep the <tt>--</tt> that usually separates options from
431 non-option arguments.
432</p>
433</dd>
434<dt>
435<tt>PARSE_OPT_STOP_AT_NON_OPTION</tt>
436</dt>
437<dd>
438<p>
439 Usually the whole argument vector is massaged and reordered.
440 Using this flag, processing is stopped at the first non-option
441 argument.
442</p>
443</dd>
Junio C Hamano18f51402009-03-10 16:39:13444<dt>
445<tt>PARSE_OPT_KEEP_ARGV0</tt>
446</dt>
447<dd>
448<p>
449 Keep the first argument, which contains the program name. It's
450 removed from argv[] by default.
451</p>
452</dd>
453<dt>
454<tt>PARSE_OPT_KEEP_UNKNOWN</tt>
455</dt>
456<dd>
457<p>
458 Keep unknown arguments instead of erroring out. This doesn't
459 work for all combinations of arguments as users might expect
460 it to do. E.g. if the first argument in <tt>&#8212;unknown &#8212;known</tt>
461 takes a value (which we can't know), the second one is
462 mistakenly interpreted as a known option. Similarly, if
463 <tt>PARSE_OPT_STOP_AT_NON_OPTION</tt> is set, the second argument in
464 <tt>&#8212;unknown value</tt> will be mistakenly interpreted as a
465 non-option, not as a value belonging to the unknown option,
466 the parser early. That's why parse_options() errors out if
467 both options are set.
468</p>
469</dd>
470<dt>
471<tt>PARSE_OPT_NO_INTERNAL_HELP</tt>
472</dt>
473<dd>
474<p>
475 By default, parse_options() handles <tt>-h</tt>, <tt>&#8212;help</tt> and
476 <tt>&#8212;help-all</tt> internally, by showing a help screen. This option
477 turns it off and allows one to add custom handlers for these
478 options, or to just leave them unknown.
479</p>
480</dd>
Junio C Hamano4604fe52008-09-19 06:37:10481</dl></div>
Junio C Hamano4224f992008-06-23 07:14:08482</li>
Junio C Hamano4604fe52008-09-19 06:37:10483</ol></div>
Junio C Hamano4224f992008-06-23 07:14:08484</div>
Junio C Hamano4604fe52008-09-19 06:37:10485<h2 id="_data_structure">Data Structure</h2>
Junio C Hamano4224f992008-06-23 07:14:08486<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10487<div class="para"><p>The main data structure is an array of the <tt>option</tt> struct,
Junio C Hamano4224f992008-06-23 07:14:08488say <tt>static struct option builtin_add_options[]</tt>.
Junio C Hamano4604fe52008-09-19 06:37:10489There are some macros to easily define options:</p></div>
490<div class="vlist"><dl>
Junio C Hamano4224f992008-06-23 07:14:08491<dt>
492<tt>OPT__ABBREV(&amp;int_var)</tt>
493</dt>
494<dd>
495<p>
496 Add <tt>--abbrev[=&lt;n&gt;]</tt>.
497</p>
498</dd>
499<dt>
500<tt>OPT__DRY_RUN(&amp;int_var)</tt>
501</dt>
502<dd>
503<p>
504 Add <tt>-n, --dry-run</tt>.
505</p>
506</dd>
507<dt>
508<tt>OPT__QUIET(&amp;int_var)</tt>
509</dt>
510<dd>
511<p>
512 Add <tt>-q, --quiet</tt>.
513</p>
514</dd>
515<dt>
516<tt>OPT__VERBOSE(&amp;int_var)</tt>
517</dt>
518<dd>
519<p>
520 Add <tt>-v, --verbose</tt>.
521</p>
522</dd>
523<dt>
524<tt>OPT_GROUP(description)</tt>
525</dt>
526<dd>
527<p>
528 Start an option group. <tt>description</tt> is a short string that
529 describes the group or an empty string.
530 Start the description with an upper-case letter.
531</p>
532</dd>
533<dt>
534<tt>OPT_BOOLEAN(short, long, &amp;int_var, description)</tt>
535</dt>
536<dd>
537<p>
538 Introduce a boolean option.
539 <tt>int_var</tt> is incremented on each use.
540</p>
541</dd>
542<dt>
543<tt>OPT_BIT(short, long, &amp;int_var, description, mask)</tt>
544</dt>
545<dd>
546<p>
547 Introduce a boolean option.
548 If used, <tt>int_var</tt> is bitwise-ored with <tt>mask</tt>.
549</p>
550</dd>
551<dt>
Junio C Hamano7ae18252009-05-23 09:53:32552<tt>OPT_NEGBIT(short, long, &amp;int_var, description, mask)</tt>
553</dt>
554<dd>
555<p>
556 Introduce a boolean option.
557 If used, <tt>int_var</tt> is bitwise-anded with the inverted <tt>mask</tt>.
558</p>
559</dd>
560<dt>
Junio C Hamano4224f992008-06-23 07:14:08561<tt>OPT_SET_INT(short, long, &amp;int_var, description, integer)</tt>
562</dt>
563<dd>
564<p>
565 Introduce a boolean option.
566 If used, set <tt>int_var</tt> to <tt>integer</tt>.
567</p>
568</dd>
569<dt>
570<tt>OPT_SET_PTR(short, long, &amp;ptr_var, description, ptr)</tt>
571</dt>
572<dd>
573<p>
574 Introduce a boolean option.
575 If used, set <tt>ptr_var</tt> to <tt>ptr</tt>.
576</p>
577</dd>
578<dt>
579<tt>OPT_STRING(short, long, &amp;str_var, arg_str, description)</tt>
580</dt>
581<dd>
582<p>
583 Introduce an option with string argument.
584 The string argument is put into <tt>str_var</tt>.
585</p>
586</dd>
587<dt>
588<tt>OPT_INTEGER(short, long, &amp;int_var, description)</tt>
589</dt>
590<dd>
591<p>
592 Introduce an option with integer argument.
593 The integer is put into <tt>int_var</tt>.
594</p>
595</dd>
596<dt>
597<tt>OPT_DATE(short, long, &amp;int_var, description)</tt>
598</dt>
599<dd>
600<p>
601 Introduce an option with date argument, see <tt>approxidate()</tt>.
602 The timestamp is put into <tt>int_var</tt>.
603</p>
604</dd>
605<dt>
606<tt>OPT_CALLBACK(short, long, &amp;var, arg_str, description, func_ptr)</tt>
607</dt>
608<dd>
609<p>
610 Introduce an option with argument.
611 The argument will be fed into the function given by <tt>func_ptr</tt>
612 and the result will be put into <tt>var</tt>.
613 See <em>Option Callbacks</em> below for a more elaborate description.
614</p>
615</dd>
616<dt>
Junio C Hamano3d141512009-06-01 01:22:40617<tt>OPT_FILENAME(short, long, &amp;var, description)</tt>
618</dt>
619<dd>
620<p>
621 Introduce an option with a filename argument.
622 The filename will be prefixed by passing the filename along with
623 the prefix argument of <tt>parse_options()</tt> to <tt>prefix_filename()</tt>.
624</p>
625</dd>
626<dt>
Junio C Hamano4224f992008-06-23 07:14:08627<tt>OPT_ARGUMENT(long, description)</tt>
628</dt>
629<dd>
630<p>
631 Introduce a long-option argument that will be kept in <tt>argv[]</tt>.
632</p>
633</dd>
Junio C Hamano7ae18252009-05-23 09:53:32634<dt>
635<tt>OPT_NUMBER_CALLBACK(&amp;var, description, func_ptr)</tt>
636</dt>
637<dd>
638<p>
639 Recognize numerical options like -123 and feed the integer as
640 if it was an argument to the function given by <tt>func_ptr</tt>.
641 The result will be put into <tt>var</tt>. There can be only one such
642 option definition. It cannot be negated and it takes no
643 arguments. Short options that happen to be digits take
644 precedence over it.
645</p>
646</dd>
Junio C Hamano4604fe52008-09-19 06:37:10647</dl></div>
648<div class="para"><p>The last element of the array must be <tt>OPT_END()</tt>.</p></div>
649<div class="para"><p>If not stated otherwise, interpret the arguments as follows:</p></div>
650<div class="ilist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08651<li>
652<p>
653<tt>short</tt> is a character for the short option
654 (e.g. <tt>'e'</tt> for <tt>-e</tt>, use <tt>0</tt> to omit),
655</p>
656</li>
657<li>
658<p>
659<tt>long</tt> is a string for the long option
660 (e.g. <tt>"example"</tt> for <tt>--example</tt>, use <tt>NULL</tt> to omit),
661</p>
662</li>
663<li>
664<p>
665<tt>int_var</tt> is an integer variable,
666</p>
667</li>
668<li>
669<p>
670<tt>str_var</tt> is a string variable (<tt>char *</tt>),
671</p>
672</li>
673<li>
674<p>
675<tt>arg_str</tt> is the string that is shown as argument
676 (e.g. <tt>"branch"</tt> will result in <tt>&lt;branch&gt;</tt>).
677 If set to <tt>NULL</tt>, three dots (<tt>&#8230;</tt>) will be displayed.
678</p>
679</li>
680<li>
681<p>
682<tt>description</tt> is a short string to describe the effect of the option.
683 It shall begin with a lower-case letter and a full stop (<tt>.</tt>) shall be
684 omitted at the end.
685</p>
686</li>
Junio C Hamano4604fe52008-09-19 06:37:10687</ul></div>
Junio C Hamano4224f992008-06-23 07:14:08688</div>
Junio C Hamano4604fe52008-09-19 06:37:10689<h2 id="_option_callbacks">Option Callbacks</h2>
Junio C Hamano4224f992008-06-23 07:14:08690<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10691<div class="para"><p>The function must be defined in this form:</p></div>
Junio C Hamano4224f992008-06-23 07:14:08692<div class="literalblock">
693<div class="content">
694<pre><tt>int func(const struct option *opt, const char *arg, int unset)</tt></pre>
695</div></div>
Junio C Hamano4604fe52008-09-19 06:37:10696<div class="para"><p>The callback mechanism is as follows:</p></div>
697<div class="ilist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08698<li>
699<p>
Junio C Hamanod4f35a92009-05-17 05:39:29700Inside <tt>func</tt>, the only interesting member of the structure
Junio C Hamano4224f992008-06-23 07:14:08701 given by <tt>opt</tt> is the void pointer <tt>opt-&gt;value</tt>.
702 <tt>*opt-&gt;value</tt> will be the value that is saved into <tt>var</tt>, if you
703 use <tt>OPT_CALLBACK()</tt>.
704 For example, do <tt>*(unsigned long *)opt-&gt;value = 42;</tt> to get 42
705 into an <tt>unsigned long</tt> variable.
706</p>
707</li>
708<li>
709<p>
710Return value <tt>0</tt> indicates success and non-zero return
711 value will invoke <tt>usage_with_options()</tt> and, thus, die.
712</p>
713</li>
714<li>
715<p>
716If the user negates the option, <tt>arg</tt> is <tt>NULL</tt> and <tt>unset</tt> is 1.
717</p>
718</li>
Junio C Hamano4604fe52008-09-19 06:37:10719</ul></div>
Junio C Hamano4224f992008-06-23 07:14:08720</div>
Junio C Hamano4604fe52008-09-19 06:37:10721<h2 id="_sophisticated_option_parsing">Sophisticated option parsing</h2>
Junio C Hamano4224f992008-06-23 07:14:08722<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10723<div class="para"><p>If you need, for example, option callbacks with optional arguments
Junio C Hamano4224f992008-06-23 07:14:08724or without arguments at all, or if you need other special cases,
725that are not handled by the macros above, you need to specify the
Junio C Hamano4604fe52008-09-19 06:37:10726members of the <tt>option</tt> structure manually.</p></div>
727<div class="para"><p>This is not covered in this document, but well documented
728in <tt>parse-options.h</tt> itself.</p></div>
Junio C Hamano4224f992008-06-23 07:14:08729</div>
Junio C Hamano4604fe52008-09-19 06:37:10730<h2 id="_examples">Examples</h2>
Junio C Hamano4224f992008-06-23 07:14:08731<div class="sectionbody">
Junio C Hamano4604fe52008-09-19 06:37:10732<div class="para"><p>See <tt>test-parse-options.c</tt> and
Junio C Hamano4224f992008-06-23 07:14:08733<tt>builtin-add.c</tt>,
734<tt>builtin-clone.c</tt>,
735<tt>builtin-commit.c</tt>,
736<tt>builtin-fetch.c</tt>,
737<tt>builtin-fsck.c</tt>,
738<tt>builtin-rm.c</tt>
Junio C Hamano4604fe52008-09-19 06:37:10739for real-world examples.</p></div>
Junio C Hamano4224f992008-06-23 07:14:08740</div>
Junio C Hamano3dac5042007-12-15 08:40:54741<div id="footer">
742<div id="footer-text">
Junio C Hamano3d141512009-06-01 01:22:40743Last updated 2009-06-01 01:22:22 UTC
Junio C Hamano3dac5042007-12-15 08:40:54744</div>
745</div>
746</body>
747</html>