• 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/env_options.cpp
1
// Copyright Thomas Kent 2016
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
#include <hpx/modules/program_options.hpp>
8

9
#include <algorithm>
10
#include <cctype>
11
#include <functional>
12
#include <iostream>
13
#include <string>
14

15
#include <hpx/config/warnings_prefix.hpp>
16

17
namespace po = hpx::program_options;
×
18

19
std::string mapper(std::string env_var)
20
{
21
    // ensure the env_var is all caps
×
22
    std::transform(env_var.begin(), env_var.end(), env_var.begin(),
23
        [](char c) { return std::toupper(c); });
×
24

×
25
    if (env_var == "PATH")
×
26
        return "path";
×
27
    if (env_var == "EXAMPLE_VERBOSE")
28
        return "verbosity";
×
29

30
    return "";
31
}
×
32

33
void get_env_options()
×
34
{
35
    po::options_description config("Configuration");
×
36
    // clang-format off
×
37
    config.add_options()
×
38
        ("path", "the execution path")
39
        ("verbosity", po::value<std::string>()->default_value("INFO"),
40
         "set verbosity: DEBUG, INFO, WARN, ERROR, FATAL")
41
        ;
42
    // clang-format on
×
43

×
44
    po::variables_map vm;
×
45
    store(po::parse_environment(
46
              config, std::function<std::string(std::string)>(mapper)),
×
47
        vm);
48
    notify(vm);
×
49

50
    if (vm.count("path"))
×
51
    {
×
52
        std::cout << "First 75 chars of the system path: \n";
53
        std::cout << vm["path"].as<std::string>().substr(0, 75) << std::endl;
54
    }
×
55

56
    std::cout << "Verbosity: " << vm["verbosity"].as<std::string>()
×
57
              << std::endl;
58
}
×
59

60
int main()
×
61
{
62
    get_env_options();
63

64
    return 0;
65
}
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