-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargsHandler.cpp
More file actions
67 lines (56 loc) · 1.44 KB
/
argsHandler.cpp
File metadata and controls
67 lines (56 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "CAE/ArgsHandler.hpp"
#include "CAE/Common.hpp"
#include "Utils/Env.hpp"
#include <iostream>
cae::ArgsConfig cae::ArgsHandler::ParseArgs(const int argc, const char *const *argv)
{
ArgsConfig config;
config.run = true;
if (argc <= 1)
{
return config;
}
for (int i = 1; i < argc; ++i)
{
std::string arg = argv[i];
if (arg == "-h" || arg == "--help")
{
std::cout << MESSAGE::HELP_MSG;
config.run = false;
return config;
}
if (arg == "-v" || arg == "--version")
{
std::cout << MESSAGE::VERSION_MSG;
config.run = false;
return config;
}
if (arg == "-c" || arg == "--config")
{
if (i + 1 >= argc)
{
throw std::runtime_error("Missing value for argument " + arg);
}
config.config_path = argv[++i];
}
else
{
throw std::runtime_error("Unknown argument: " + arg + ". Use -h or --help to see available options.");
}
}
return config;
}
cae::EnvConfig cae::ArgsHandler::ParseEnv(const char *const *envp)
{
EnvConfig config;
const auto envMap = utl::getEnvMap(envp);
if (envMap.contains("USER"))
{
config.user_name = envMap.at("USER");
}
if (envMap.contains("PWD"))
{
config.pwd = envMap.at("PWD");
}
return config;
}