ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
config.cpp
Go to the documentation of this file.
4
6 fs::path cwd = fs::current_path();
7
8 base_path = cwd / "tests/e2e/current/tmp/arkanjo";
9 third_party_dir = cwd / "third-party";
10}
11
13 base_path = CONFIG_VALUE(ARKANJO_CACHE_PATH, [this](auto v) -> std::filesystem::path {
14 if (v.has_value()) {
15 return fs::path(*v) / program_name;
16 }
17
18 const char* cache_env = std::getenv("XDG_CACHE_HOME");
19 const char* home = std::getenv("HOME");
20
21 if (cache_env) {
22 return fs::path(cache_env) / program_name;
23 } else if (home) {
24 return fs::path(home) / ".cache" / program_name;
25 } else {
26 FormatterManager::warn("neither XDG_CACHE_HOME nor HOME is set. Using default path.");
27 }
28
29 return base_path;
30 });
31
32 theme = CONFIG_VALUE(THEME_MODE, [](auto v) -> config::Theme {
33 if (v.has_value()) {
34 std::string_view mode = *v;
35 return (mode == "dark") ? config::Theme::Dark : config::Theme::Light;
36 }
37
41 });
42
43 third_party_dir = CONFIG_VALUE(ARKANJO_THIRD_PARTY_DIR, [this](auto v) -> std::filesystem::path {
44 return v.has_value()
45 ? fs::path(*v)
47 });
48
49 project_version = CONFIG_VALUE(ARKANJO_PROJECT_VERSION, [this](auto v) -> std::filesystem::path {
50 return v.has_value()
51 ? *v
53 });
54
55 validate();
56}
57
58void Config::validate() {
59 if (base_path.empty() || !fs::exists(third_party_dir) || !fs::is_directory(third_party_dir)) {
60 throw std::runtime_error("Could not locate base-path directory");
61 }
62
63 if (!fs::exists(third_party_dir) || !fs::is_directory(third_party_dir)) {
64 throw std::runtime_error("Could not locate third-party directory");
65 }
66}
67
69 static Config instance;
70 return instance;
71}
Singleton configuration manager class.
Definition: config.hpp:24
static Config & config()
Gets the singleton configuration instance.
Definition: config.cpp:68
void setDefaultConfig()
Sets default production configuration paths.
Definition: config.cpp:12
void setTestConfig()
Sets test configuration paths.
Definition: config.cpp:5
static void warn(const std::string &str)
static bool is_bg_color_dark()
Determines if terminal background color is dark.
Configuration management interface.
Theme
Definition: schema.hpp:7
#define CONFIG_VALUE(name, fallback_lambda)
Definition: resolver.hpp:22
std::filesystem::path base_path
Default base path for temporary files.
Definition: schema.hpp:16
std::filesystem::path third_party_dir
Directory containing third-party dependencies.
Definition: schema.hpp:17
std::string project_version
Current project version.
Definition: schema.hpp:19
std::string program_name
Name of the program.
Definition: schema.hpp:15
config::Theme theme
Current terminal theme.
Definition: schema.hpp:27