diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/cli.hpp | 12 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 13 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index 865ef500..da67d8e7 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -51,7 +51,7 @@ struct LogArguments { /// \brief Arguments required for analysing targets. struct AnalysisArguments { std::optional<std::size_t> expression_log_limit{}; - std::string defines{}; + std::vector<std::string> defines{}; std::filesystem::path config_file{}; std::optional<nlohmann::json> target{}; std::optional<std::string> request_action_input{}; @@ -218,12 +218,14 @@ static inline auto SetupAnalysisArguments( "in error messages (Default {})", Evaluator::kDefaultExpressionLogLimit)) ->type_name("NUM"); - app->add_option( + app->add_option_function<std::string>( "-D,--defines", - clargs->defines, + [clargs](auto const& d) { clargs->defines.emplace_back(d); }, "Define an overlay configuration via an in-line JSON object." - "Latest wins.") - ->type_name("JSON"); + " Multiple options overlay.") + ->type_name("JSON") + ->trigger_on_parse(); // run callback on all instances while parsing, + // not after all parsing is done app->add_option( "-c,--config", clargs->config_file, "Path to configuration file.") ->type_name("PATH"); diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 98812abd..869ed146 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -487,21 +487,20 @@ void SetupHashFunction() { } } - if (not clargs.defines.empty()) { + for (auto const& s : clargs.defines) { try { - auto map = - Expression::FromJson(nlohmann::json::parse(clargs.defines)); + auto map = Expression::FromJson(nlohmann::json::parse(s)); if (not map->IsMap()) { Logger::Log(LogLevel::Error, - "Defines {} does not contain a map.", - clargs.defines); + "Defines entry {} does not contain a map.", + nlohmann::json(s).dump()); std::exit(kExitFailure); } config = config.Update(map); } catch (std::exception const& e) { Logger::Log(LogLevel::Error, - "Parsing defines {} failed with error:\n{}", - clargs.defines, + "Parsing defines entry {} failed with error:\n{}", + nlohmann::json(s).dump(), e.what()); std::exit(kExitFailure); } |