diff --git a/src/commands.cpp b/src/commands.cpp index 34934bc..6147a1a 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -319,12 +319,16 @@ clipp::group build_command::do_group() (clipp::option("-n", "--new") >> clean_) % "deletes everything and starts from scratch", - (clipp::option("-p", "--no-pull") >> nopull_) - % "clones repos if necessary, but never pulls once cloned", + ( + clipp::option("--pull").call([&]{ nopull_ = false; }) | + clipp::option("--no-pull").call([&]{ nopull_ = true; }) + ) % "whether to pull repos that are already cloned; global override", - (clipp::option("--revert-ts") >> revert_ts_) - % "reverts all the .ts files in a repo before pulling to avoid " - "merge errors", + ( + clipp::option("--revert-ts").call([&]{ revert_ts_ = true; }) | + clipp::option("--no-revert-ts").call([&]{ revert_ts_ = false; }) + ) % "whether to revert all the .ts files in a repo before pulling to " + "avoid merge errors; global override", (clipp::option("--keep-msbuild") >> keep_msbuild_) % "don't terminate msbuild.exe instances after building", @@ -349,10 +353,20 @@ void build_command::convert_cl_to_conf() common.options.push_back("global/rebuild=true"); if (nopull_) - common.options.push_back("options/no_pull=true"); + { + if (*nopull_) + common.options.push_back("_override:options/no_pull=true"); + else + common.options.push_back("_override:options/no_pull=false"); + } if (revert_ts_) - common.options.push_back("options/revert_ts=true"); + { + if (*revert_ts_) + common.options.push_back("_override:options/revert_ts=true"); + else + common.options.push_back("_override:options/revert_ts=false"); + } } int build_command::do_run() diff --git a/src/commands.h b/src/commands.h index 9190e6d..4c01a0e 100644 --- a/src/commands.h +++ b/src/commands.h @@ -113,9 +113,9 @@ private: bool reextract_ = false; bool rebuild_ = false; bool clean_ = false; - bool nopull_ = false; + std::optional nopull_; bool keep_msbuild_ = false; - bool revert_ts_ = false; + std::optional revert_ts_; void terminate_msbuild(); }; diff --git a/src/conf.cpp b/src/conf.cpp index bf345b3..9bfe737 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -73,43 +73,59 @@ void conf::add_global( map_[""][section][key] = value; } +std::optional conf::find_for_task( + const std::string& task_name, + const std::string& section_name, const std::string& key) +{ + auto titor = map_.find(task_name); + if (titor == map_.end()) + return {}; + + const auto& task = titor->second; + + auto sitor = task.find(section_name); + if (sitor == task.end()) + return {}; + + const auto& section = sitor->second; + + auto itor = section.find(key); + if (itor == section.end()) + return {}; + + return itor->second; +} + std::string conf::get_for_task( const std::vector& task_names, const std::string& section, const std::string& key) { task_map::iterator task = map_.end(); + auto v = find_for_task("_override", section, key); + if (v) + return *v; + for (auto&& tn : task_names) { - task = map_.find(tn); - if (task != map_.end()) - break; + v = find_for_task(tn, section, key); + if (v) + return *v; } - if (task == map_.end()) + for (auto&& tn : task_names) { - for (auto&& tn : task_names) + if (is_super_task(tn)) { - if (is_super_task(tn)) - { - task = map_.find("super"); - break; - } + v = find_for_task("super", section, key); + if (v) + return *v; + + break; } } - if (task == map_.end()) - return get_global(section, key); - - auto sitor = task->second.find(section); - if (sitor == task->second.end()) - return get_global(section, key); - - auto kitor = sitor->second.find(key); - if (kitor == sitor->second.end()) - return get_global(section, key); - - return kitor->second; + return get_global(section, key); } void conf::set_for_task( @@ -692,7 +708,7 @@ void parse_section( } else { - if (!task_exists(task)) + if (!task_exists(task) && task != "_override") ini_error(ini, i, "task '" + task + "' doesn't exist"); conf::set_for_task(task, section, k, v); @@ -929,7 +945,7 @@ void init_options( } else { - if (!task_exists(po.task)) + if (!task_exists(po.task) && po.task != "_override") { gcx().bail_out(context::generic, "task '{}' doesn't exist (command line option)", diff --git a/src/conf.h b/src/conf.h index 21b8ea0..38205c2 100644 --- a/src/conf.h +++ b/src/conf.h @@ -69,6 +69,10 @@ private: static int output_log_level_; static int file_log_level_; static bool dry_; + + static std::optional find_for_task( + const std::string& task_name, + const std::string& section, const std::string& key); };