• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/program_options/examples/option_groups.cpp
1
// Copyright Vladimir Prus 2002-2004.
2
//  SPDX-License-Identifier: BSL-1.0
3
// Distributed under the Boost Software License, Version 1.0.
4
// (See accompanying file LICENSE_1_0.txt
5
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
/** This example shows how to handle options groups.
8

9
    For a test, run:
10

11
    option_groups --help
12
    option_groups --num-threads 10
13
    option_groups --help-module backend
14

15
    The first invocation would show to option groups, and will not show the
16
    '--num-threads' options. The second invocation will still get the value of
17
    the hidden '--num-threads' option. Finally, the third invocation will show
18
    the options for the 'backend' module, including the '--num-threads' option.
19

20
*/
21

22
#include <hpx/modules/program_options.hpp>
23

24
#include <exception>
25
#include <fstream>
26
#include <iostream>
27
#include <string>
28

29
#include <hpx/config/warnings_prefix.hpp>
30

31
using namespace hpx::program_options;
32
using namespace std;
×
33

34
int main(int ac, char* av[])
35
{
36
    try
37
    {
×
38
        // Declare three groups of options.
39
        options_description general("General options");
×
40
        // clang-format off
×
41
        general.add_options()
×
42
            ("help", "produce a help message")
43
            ("help-module", value<string>(),
×
44
                "produce a help for a given module")
45
            ("version", "output the version number")
46
            ;
47
        // clang-format on
×
48

×
49
        options_description gui("GUI options");
50
        gui.add_options()("display", value<string>(), "display to use");
×
51

52
        options_description backend("Backend options");
×
53
        // clang-format off
×
54
        backend.add_options()
55
            ("num-threads", value<int>(), "the initial number of threads")
56
            ;
57
        // clang-format on
58

59
        // Declare an options description instance which will include
×
60
        // all the options
×
61
        options_description all("Allowed options");
62
        all.add(general).add(gui).add(backend);
63

64
        // Declare an options description instance which will be shown
×
65
        // to the user
×
66
        options_description visible("Allowed options");
67
        visible.add(general).add(gui);
×
68

×
69
        variables_map vm;
70
        store(parse_command_line(ac, av, all), vm);
×
71

72
        if (vm.count("help"))
×
73
        {
74
            cout << visible;
75
            return 0;
×
76
        }
77
        if (vm.count("help-module"))
×
78
        {
×
79
            auto const& s = vm["help-module"].as<string>();
80
            if (s == "gui")
×
81
            {
82
                cout << gui;
×
83
            }
84
            else if (s == "backend")
×
85
            {
86
                cout << backend;
87
            }
88
            else
89
            {
×
90
                cout << "Unknown module '" << s
91
                     << "' in the --help-module option\n";
92
                return 1;
×
93
            }
94
            return 0;
×
95
        }
96
        if (vm.count("num-threads"))
97
        {
×
98
            cout << "The 'num-threads' options was set to "
99
                 << vm["num-threads"].as<int>() << "\n";
×
100
        }
×
101
    }
102
    catch (std::exception const& e)
×
103
    {
×
104
        cout << e.what() << "\n";
105
    }
106
    return 0;
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc