1 | #include <boost/program_options.hpp>
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 | #include <stdexcept>
|
---|
5 | #include <string>
|
---|
6 |
|
---|
7 | int main(int argc, char* argv[])
|
---|
8 | {
|
---|
9 | try
|
---|
10 | {
|
---|
11 | boost::program_options::options_description desc("Allowed options");
|
---|
12 | desc.add_options()
|
---|
13 | ("help,h", "produce help message")
|
---|
14 | ("enable-debug", "enables debug output.")
|
---|
15 | ;
|
---|
16 |
|
---|
17 | boost::program_options::variables_map vm;
|
---|
18 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
|
---|
19 | boost::program_options::notify(vm);
|
---|
20 |
|
---|
21 | if (vm.count("help") || (argc == 1))
|
---|
22 | {
|
---|
23 | std::cout << "To reproduce the bug call " << argv[0] << " --enable-debug --enable-debug" << std::endl
|
---|
24 | << std::endl
|
---|
25 | << " On Windows the option name '--enable-debug' is contained as expected in the error message:" << std::endl
|
---|
26 | << " option '--enable-debug' cannot be specified more than once" << std::endl
|
---|
27 | << std::endl
|
---|
28 | << " On Linux only the last part of the option name '--enable-debug' (=> '--debug') is contained in the error message:" << std::endl
|
---|
29 | << " option '--debug' cannot be specified more than once" << std::endl
|
---|
30 | << std::endl
|
---|
31 | << "Options:" << std::endl;
|
---|
32 |
|
---|
33 | std::cout << desc << std::endl;
|
---|
34 | if (argc > 1)
|
---|
35 | {
|
---|
36 | return 0;
|
---|
37 | }
|
---|
38 | else
|
---|
39 | {
|
---|
40 | return 1;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | if (vm.count("enable-debug"))
|
---|
45 | {
|
---|
46 | std::cout << "Activating debug output." << std::endl;
|
---|
47 | }
|
---|
48 |
|
---|
49 | std::cout << "Program continues" << std::endl;
|
---|
50 | }
|
---|
51 | catch (const std::exception& e)
|
---|
52 | {
|
---|
53 | std::cout << e.what() << std::endl;
|
---|
54 | }
|
---|
55 |
|
---|
56 | return 0;
|
---|
57 | }
|
---|
58 |
|
---|