mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-11-17 02:25:59 +01:00
configOptions: add allowMissingConfig
This commit is contained in:
parent
0d7d03363b
commit
1210de188c
2 changed files with 20 additions and 3 deletions
|
@ -69,6 +69,12 @@ namespace Hyprlang {
|
||||||
Return all errors instead of just the first
|
Return all errors instead of just the first
|
||||||
*/
|
*/
|
||||||
bool throwAllErrors = false;
|
bool throwAllErrors = false;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@since 0.2.0
|
||||||
|
Don't throw on a missing config file. Carry on as if nothing happened.
|
||||||
|
*/
|
||||||
|
bool allowMissingConfig = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -32,10 +32,17 @@ CConfig::CConfig(const char* path, const Hyprlang::SConfigOptions& options) {
|
||||||
impl = new CConfigImpl;
|
impl = new CConfigImpl;
|
||||||
try {
|
try {
|
||||||
impl->path = std::filesystem::canonical(path);
|
impl->path = std::filesystem::canonical(path);
|
||||||
} catch (std::exception& e) { throw "Couldn't open file. File does not exist"; }
|
} catch (std::exception& e) {
|
||||||
|
if (!options.allowMissingConfig)
|
||||||
|
throw "Couldn't open file. File does not exist";
|
||||||
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists(impl->path))
|
if (!std::filesystem::exists(impl->path)) {
|
||||||
throw "File does not exist";
|
if (!options.allowMissingConfig)
|
||||||
|
throw "File does not exist";
|
||||||
|
|
||||||
|
impl->path = "";
|
||||||
|
}
|
||||||
|
|
||||||
impl->envVariables.clear();
|
impl->envVariables.clear();
|
||||||
for (char** env = environ; *env; ++env) {
|
for (char** env = environ; *env; ++env) {
|
||||||
|
@ -496,6 +503,10 @@ CParseResult CConfig::parse() {
|
||||||
applyDefaultsToCat(*sc);
|
applyDefaultsToCat(*sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// implies options.allowMissingConfig
|
||||||
|
if (impl->path.empty())
|
||||||
|
return CParseResult{};
|
||||||
|
|
||||||
CParseResult fileParseResult = parseFile(impl->path);
|
CParseResult fileParseResult = parseFile(impl->path);
|
||||||
|
|
||||||
return fileParseResult;
|
return fileParseResult;
|
||||||
|
|
Loading…
Reference in a new issue