From c08c63a4003df9d0761ab227599620b60c110af3 Mon Sep 17 00:00:00 2001 From: srpurba Date: Thu, 6 Oct 2022 19:49:54 -0400 Subject: [PATCH] sample data and input config --- app/main.cpp | 19 ++++++++++++++++--- config.json | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 config.json diff --git a/app/main.cpp b/app/main.cpp index dc38f99..9530f7b 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -17,7 +17,6 @@ argparse::ArgumentParser setup_parser(const std::vector &argv) { .default_value(std::string( "https://cdn.jsdelivr.net/gh/kimeiga/bahunya/dist/bahunya.min.css")) .help("The stylesheet file link"); - // check if the stylesheet flag is valid url program.add_argument("-c", "--config").help("The config JSON file"); if (!(std::count(argv.begin(), argv.end(), "-c") or std::count(argv.begin(), argv.end(), "--config"))) { @@ -27,8 +26,6 @@ argparse::ArgumentParser setup_parser(const std::vector &argv) { } else { program.add_argument("-i", "--input").help("The input file / directory"); } - - return program; } @@ -56,6 +53,22 @@ int main(int argc, char const *argv[]) { std::cerr << "Configuration file not found at: " << *p_value << std::endl; std::exit(1); } + nlohmann::json config_json; + stream >> config_json; + + if (config_json.find("input") == config_json.end()) { + std::cerr << "Input file / directory not specified in config file" + << std::endl; + std::exit(1); + } + + if (auto fn = program.present("-i")) + options["input"] = *fn; + + for (auto &el : config_json.items()) + options[el.key()] = el.value(); + } else { + options["input"] = program.get("-i"); } Palpatine palpatine(options["output"].c_str(), options["input"].c_str(), diff --git a/config.json b/config.json new file mode 100644 index 0000000..df1e9c7 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "input": "./data", + "output": "." +} \ No newline at end of file