@@ -21,7 +21,7 @@ options groups/hidden options
21
21
-->
22
22
<section >
23
23
<title >Non-conventional Syntax</title >
24
-
24
+
25
25
<para >Sometimes, standard command line syntaxes are not enough. For
26
26
example, the gcc compiler has "-frtti" and -fno-rtti" options, and this
27
27
syntax is not directly supported.
@@ -57,14 +57,14 @@ store(command_line_parser(ac, av).options(desc).extra_parser(reg_foo)
57
57
.run(), vm);
58
58
</programlisting >
59
59
The complete example can be found in the "example/custom_syntax.cpp"
60
- file.
60
+ file.
61
61
</para >
62
62
</section >
63
63
64
64
<section >
65
65
<title >Response Files</title >
66
66
67
- <indexterm ><primary >response files</primary ></indexterm >
67
+ <indexterm ><primary >response files</primary ></indexterm >
68
68
69
69
<para >Some operating system have very low limits of the command line
70
70
length. The common way to work around those limitations is using
@@ -79,7 +79,7 @@ store(command_line_parser(ac, av).options(desc).extra_parser(reg_foo)
79
79
<para >
80
80
First, you need to define an option for the response file:
81
81
<programlisting >
82
- ("response-file", value< string> (),
82
+ ("response-file", value< string> (),
83
83
"can be specified with '@name', too")
84
84
</programlisting >
85
85
</para >
@@ -120,14 +120,14 @@ if (vm.count("response-file")) {
120
120
vector<string> args;
121
121
copy(tok.begin(), tok.end(), back_inserter(args));
122
122
// Parse the file and store the options
123
- store(command_line_parser(args).options(desc).run(), vm);
123
+ store(command_line_parser(args).options(desc).run(), vm);
124
124
}
125
125
]]>
126
126
</programlisting >
127
127
The complete example can be found in the "example/response_file.cpp"
128
- file.
128
+ file.
129
129
</para >
130
-
130
+
131
131
</section >
132
132
133
133
<section >
@@ -146,7 +146,7 @@ if (vm.count("response-file")) {
146
146
<programlisting >
147
147
vector< string> args = split_winmain(lpCmdLine);
148
148
store(command_line_parser(args).options(desc).run(), vm);
149
- </programlisting >
149
+ </programlisting >
150
150
The <code >split_winmain</code > function is overloaded for <code >wchar_t</code > strings, so can
151
151
also be used in Unicode applications.
152
152
</para >
@@ -223,7 +223,7 @@ visible.add(general).add(gui);
223
223
variables_map vm;
224
224
store(parse_command_line(ac, av, all), vm);
225
225
226
- if (vm.count("help"))
226
+ if (vm.count("help"))
227
227
{
228
228
cout << visible;
229
229
return 0;
@@ -235,16 +235,16 @@ if (vm.count("help-module")) {
235
235
} else if (s == "backend") {
236
236
cout << backend;
237
237
} else {
238
- cout << "Unknown module '"
238
+ cout << "Unknown module '"
239
239
<< s << "' in the --help-module option\n";
240
240
return 1;
241
241
}
242
242
return 0;
243
243
}
244
244
if (vm.count("num-threads")) {
245
245
cout << "The 'num-threads' options was set to "
246
- << vm["num-threads"].as<int>() << "\n";
247
- }
246
+ << vm["num-threads"].as<int>() << "\n";
247
+ }
248
248
]]> </programlisting >
249
249
When parsing the command line, all options are allowed. The "--help"
250
250
message, however, does not include the "Backend options" group -- the
@@ -253,7 +253,7 @@ if (vm.count("num-threads")) {
253
253
option. The complete example can be found in the
254
254
"example/option_groups.cpp" file.
255
255
</para >
256
-
256
+
257
257
</section >
258
258
259
259
<section >
@@ -276,7 +276,7 @@ public:
276
276
};
277
277
]]> </programlisting > and then overload the <code >validate</code > function:
278
278
<programlisting ><![CDATA[
279
- void validate(boost::any& v,
279
+ void validate(boost::any& v,
280
280
const std::vector<std::string>& values,
281
281
magic_number* target_type, int)
282
282
{
@@ -290,16 +290,16 @@ void validate(boost::any& v,
290
290
// one string, it's an error, and exception will be thrown.
291
291
const string& s = validators::get_single_string(values);
292
292
293
- // Do regex match and convert the interesting part to
293
+ // Do regex match and convert the interesting part to
294
294
// int.
295
295
smatch match;
296
296
if (regex_match(s, match, r)) {
297
297
v = any(magic_number(lexical_cast<int>(match[1])));
298
298
} else {
299
299
throw validation_error(validation_error::invalid_option_value);
300
- }
300
+ }
301
301
}
302
- ]]>
302
+ ]]>
303
303
</programlisting >The function takes four parameters. The first is the storage
304
304
for the value, and in this case is either empty or contains an instance of
305
305
the <code >magic_number</code > class. The second is the list of strings
@@ -372,7 +372,7 @@ void validate(boost::any& v,
372
372
locale::global(locale(""));
373
373
</programlisting >
374
374
which would set up the conversion facet according to the user's selected
375
- locale.
375
+ locale.
376
376
</para >
377
377
378
378
<para >It's wise to check the status of the C++ locale support on your
@@ -382,7 +382,7 @@ locale::global(locale(""));
382
382
<para >Go the the "test" directory and build the "test_convert" binary.</para >
383
383
</listitem >
384
384
<listitem >
385
- <para >Set some non-ascii locale in the environmemt . On Linux, one can
385
+ <para >Set some non-ascii locale in the environment . On Linux, one can
386
386
run, for example: <screen >
387
387
$ export LC_CTYPE=ru_RU.KOI8-R
388
388
</screen >
@@ -402,37 +402,37 @@ $ export LC_CTYPE=ru_RU.KOI8-R
402
402
<section >
403
403
<title >Allowing Unknown Options</title >
404
404
405
- <para >Usually, the library throws an exception on unknown option names. This
406
- behaviour can be changed. For example, only some part of your application uses
405
+ <para >Usually, the library throws an exception on unknown option names. This
406
+ behaviour can be changed. For example, only some part of your application uses
407
407
<libraryname >Program_options</libraryname >, and you wish to pass unrecognized options to another part of
408
408
the program, or even to another application.</para >
409
409
410
- <para >To allow unregistered options on the command line, you need to use
410
+ <para >To allow unregistered options on the command line, you need to use
411
411
the &basic_command_line_parser; class for parsing (not &parse_command_line; )
412
- and call the <methodname alt =" boost::program_options::basic_command_line_parser::allow_unregistered" >allow_unregistered</methodname >
412
+ and call the <methodname alt =" boost::program_options::basic_command_line_parser::allow_unregistered" >allow_unregistered</methodname >
413
413
method of that class:
414
414
<programlisting >
415
- parsed_options parsed =
416
- command_line_parser(argc, argv).options(desc).allow_unregistered().run();
415
+ parsed_options parsed =
416
+ command_line_parser(argc, argv).options(desc).allow_unregistered().run();
417
417
</programlisting >
418
-
419
- For each token that looks like an option, but does not have a known name,
420
- an instance of &basic_option; will be added to the result.
421
- The <code >string_key</code > and <code >value</code > fields of the instance will contain results
418
+
419
+ For each token that looks like an option, but does not have a known name,
420
+ an instance of &basic_option; will be added to the result.
421
+ The <code >string_key</code > and <code >value</code > fields of the instance will contain results
422
422
of syntactic parsing of the token, the <code >unregistered</code > field will be set to <code >true</code >,
423
423
and the <code >original_tokens</code > field will contain the token as it appeared on the command line.
424
424
</para >
425
425
426
- <para >If you want to pass the unrecognized options further, the
426
+ <para >If you want to pass the unrecognized options further, the
427
427
<functionname alt =" boost::program_options::collect_unrecognized" >collect_unrecognized</functionname > function can be used.
428
428
The function will collect original tokens for all unrecognized values, and optionally, all found positional options.
429
- Say, if your code handles a few options, but does not handles positional options at all, you can use the function like this:
429
+ Say, if your code handles a few options, but does not handle positional options at all, you can use the function like this:
430
430
<programlisting >
431
431
vector< string> to_pass_further = collect_unrecognized(parsed.options, include_positional);
432
432
</programlisting >
433
-
434
- </para >
435
-
433
+
434
+ </para >
435
+
436
436
</section >
437
437
438
438
</section >
0 commit comments