MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / argsToConfig

Function argsToConfig

base/base/argsToConfig.cpp:6–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <Poco/Util/MapConfiguration.h>
5
6void argsToConfig(const Poco::Util::Application::ArgVec & argv,
7 Poco::Util::LayeredConfiguration & config,
8 int priority,
9 const std::unordered_set<std::string>* alias_names)
10{
11 /// Parsing all args and converting to config layer
12 /// Test: -- --1=1 --1=2 --3 5 7 8 -9 10 -11=12 14= 15== --16==17 --=18 --19= --20 21 22 --23 --24 25 --26 -27 28 ---29=30 -- ----31 32 --33 3-4
13 Poco::AutoPtr<Poco::Util::MapConfiguration> map_config = new Poco::Util::MapConfiguration;
14 std::string key;
15
16 auto add_arg = [&map_config, &alias_names](const std::string & k, const std::string & v)
17 {
18 map_config->setString(k, v);
19
20 if (alias_names && !alias_names->contains(k))
21 {
22 std::string alias_key = k;
23 std::replace(alias_key.begin(), alias_key.end(), '-', '_');
24 if (alias_names->contains(alias_key))
25 map_config->setString(alias_key, v);
26 }
27 };
28
29 for (const auto & arg : argv)
30 {
31 auto key_start = arg.find_first_not_of('-');
32 auto pos_minus = arg.find('-');
33 auto pos_eq = arg.find('=');
34
35 // old saved '--key', will set to some true value "1"
36 if (!key.empty() && pos_minus != std::string::npos && pos_minus < key_start)
37 {
38 add_arg(key, "1");
39 key = "";
40 }
41
42 if (pos_eq == std::string::npos)
43 {
44 if (!key.empty())
45 {
46 if (pos_minus == std::string::npos || pos_minus > key_start)
47 {
48 add_arg(key, arg);
49 }
50 key = "";
51 }
52 if (pos_minus != std::string::npos && key_start != std::string::npos && pos_minus < key_start)
53 key = arg.substr(key_start);
54 continue;
55 }
56
57 key = "";
58
59
60 if (key_start == std::string::npos)
61 continue;
62
63 if (pos_minus > key_start)

Callers 2

initializeMethod · 0.85
initMethod · 0.85

Calls 10

keysMethod · 0.80
replaceFunction · 0.50
setStringMethod · 0.45
containsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected