Skip to content

Commit

Permalink
handle parse errors and recognize more options
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Mar 9, 2023
1 parent b66b153 commit c4de81f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ Flags::Flags()
void Flags::read_config_file()
{
std::ifstream ifs(config_file);
json data = json::parse(ifs);
if (data.contains("output")) output = data["output"];
if (data.contains("use-escape-codes")) use_escape_codes = data["use-escape-codes"];
try {
json data = json::parse(ifs);
if (!data.contains("layer")) return;
data = data["layer"];
if (data.contains("silent")) output = data["silent"];
if (data.contains("use-escape-codes")) use_escape_codes = data["use-escape-codes"];
if (data.contains("no-stdin")) no_stdin = data["no-stdin"];
if (data.contains("output")) output = data["output"];
} catch (const json::parse_error& e) {
std::cerr << "Could not parse config file." << std::endl;
std::exit(1);
}
}

0 comments on commit c4de81f

Please sign in to comment.