3
3
// (See accompanying file LICENSE_1_0.txt
4
4
// or copy at http://www.boost.org/LICENSE_1_0.txt)
5
5
6
- //
6
+ //
7
7
// This is an example of a program that uses multiple facets of the boost
8
- // program_options library. It will go through different types of config
8
+ // program_options library. It will go through different types of config
9
9
// options in a heirarchal manner:
10
10
// 1. Default options are set.
11
11
// 2. Command line options are set (they override defaults).
16
16
// other steps).
17
17
// 5. Default config file (default.cfg) is read, if present (it overrides
18
18
// defaults but not options from the other steps).
19
- //
19
+ //
20
20
// See the bottom of this file for full usage examples
21
21
//
22
22
@@ -217,7 +217,7 @@ class OptionsHeirarchy
217
217
std::cout << " Program Options Example " << version << std::endl;
218
218
throw OptionsExitsProgram ();
219
219
}
220
- void ParseEnvironment ()
220
+ void ParseEnvironment ()
221
221
{
222
222
store (po::parse_environment (common_options,
223
223
// The next two lines are the crazy syntax to use EnvironmentMapper as
@@ -333,16 +333,16 @@ int main(int ac, char* av[])
333
333
return 0 ;
334
334
}
335
335
336
- /*
336
+ /*
337
337
Full Usage Examples
338
338
===================
339
339
340
- These were run on windows, so some results may show that environment, but
340
+ These were run on windows, so some results may show that environment, but
341
341
results should be similar on POSIX platforms.
342
342
343
343
Help
344
344
----
345
- To see the help screen, with the available options just pass the --help (or -h)
345
+ To see the help screen, with the available options just pass the --help (or -h)
346
346
parameter. The program will then exit.
347
347
348
348
> example.exe --help
@@ -367,10 +367,10 @@ Version is similar to help (--version or -v).
367
367
368
368
Basics
369
369
------
370
- Running without any options will get the default values (path is set from the
370
+ Running without any options will get the default values (path is set from the
371
371
environment):
372
372
373
- > example.exe
373
+ > example.exe
374
374
First 75 chars of the system path:
375
375
C:\Program Files (x86)\MSBuild\14.0\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Pro
376
376
Verbosity: INFO
@@ -436,8 +436,8 @@ Or you can put the option immediately after it:
436
436
Network Address: 127.0.0.1
437
437
Network Port: 12345
438
438
439
- The include path (--include-path or -I) option allows for multiple paths to be
440
- specified (both on the command line and in config files) and combined into a
439
+ The include path (--include-path or -I) option allows for multiple paths to be
440
+ specified (both on the command line and in config files) and combined into a
441
441
vector for use by the program.
442
442
443
443
> example.exe --include-path=a/b/c --include-path d/e/f -I g/h/i -Ij/k/l
@@ -455,7 +455,7 @@ vector for use by the program.
455
455
Network Address: 127.0.0.1
456
456
Network Port: 12345
457
457
458
- There are also the option of flags that do not take parameters and just set a
458
+ There are also the option of flags that do not take parameters and just set a
459
459
boolean value to true. In this case, running the gui also causes default values
460
460
for the gui to be output to the screen.
461
461
@@ -491,7 +491,7 @@ one specifies the "master" file the others are additional files.
491
491
492
492
Environment Variables
493
493
---------------------
494
- In addition to the PATH environment variable, it also knows how to read the
494
+ In addition to the PATH environment variable, it also knows how to read the
495
495
EXAMPLE_VERBOSE environmental variable and use that to set the verbosity
496
496
option/
497
497
@@ -509,7 +509,7 @@ option/
509
509
510
510
However, if the --verboseity flag is also set, it will override the env
511
511
variable. This illustrates an important example, the way program_options works,
512
- is that a parser will not override a value that has previously been set by
512
+ is that a parser will not override a value that has previously been set by
513
513
another parser. Thus the env parser doesn't override the command line parser.
514
514
(We will see this again in config files.) Default values are seperate from this
515
515
heirarcy, they only apply if no parser has set the value and it is being read.
@@ -527,7 +527,7 @@ heirarcy, they only apply if no parser has set the value and it is being read.
527
527
Network Port: 12345
528
528
529
529
(You can unset an environmental variable with an empty set command)
530
-
530
+
531
531
> set EXAMPLE_VERBOSE=
532
532
> example.exe
533
533
First 75 chars of the system path:
@@ -544,7 +544,7 @@ heirarcy, they only apply if no parser has set the value and it is being read.
544
544
Config Files
545
545
------------
546
546
Config files generally follow the [INI file format]
547
- (https://en.wikipedia.org/wiki/INI_file) with a few exceptions.
547
+ (https://en.wikipedia.org/wiki/INI_file) with a few exceptions.
548
548
549
549
Values can be simply added tp options with an equal sign. Here are two include
550
550
paths added via the default config file (default.cfg), you can have optional
@@ -661,7 +661,7 @@ Results in a combination of all three config files:
661
661
Network Address: 5.6.7.8
662
662
Network Port: 3000
663
663
664
- Incidently the boolean run-gui option could have been set a number of ways
664
+ Incidently the boolean run-gui option could have been set a number of ways
665
665
that all result in the C++ boolean value of true:
666
666
667
667
run-gui=true
@@ -672,10 +672,10 @@ that all result in the C++ boolean value of true:
672
672
673
673
Since run-gui is an option that was set with the bool_switch type, which
674
674
forces its use on the command line without a parameter (i.e. --run-gui instead
675
- of --run-gui=true) it can't be given a "false" option, bool_switch values can
675
+ of --run-gui=true) it can't be given a "false" option, bool_switch values can
676
676
only be turned true. If instead we had a value ("my-switch", po::value<bool>())
677
- that could be set at the command line --my-switch=true or --my-switch=false, or
678
- any of the other types of boolean keywords true: true, on, 1, yes;
677
+ that could be set at the command line --my-switch=true or --my-switch=false, or
678
+ any of the other types of boolean keywords true: true, on, 1, yes;
679
679
false: false, off, 0, no. In a config file this could look like:
680
680
681
681
my-switch=true
0 commit comments