mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
conf_tool
This commit is contained in:
+17
-7
@@ -33,6 +33,16 @@ conf_global conf::global()
|
||||
return {};
|
||||
}
|
||||
|
||||
conf_task conf::task(const std::vector<std::string>& names)
|
||||
{
|
||||
return {names};
|
||||
}
|
||||
|
||||
conf_tools conf::tool()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
conf_transifex conf::transifex()
|
||||
{
|
||||
return {};
|
||||
@@ -192,11 +202,6 @@ void conf::set_for_task(
|
||||
map_[std::string(task_name)][std::string(section)][std::string(key)] = value;
|
||||
}
|
||||
|
||||
fs::path conf::tool_by_name(std::string_view name)
|
||||
{
|
||||
return get_global("tools", name);
|
||||
}
|
||||
|
||||
std::string conf::global_by_name(std::string_view name)
|
||||
{
|
||||
return get_global("global", name);
|
||||
@@ -641,7 +646,7 @@ bool try_vcvars(fs::path& bat)
|
||||
|
||||
void find_vcvars()
|
||||
{
|
||||
fs::path bat = conf::tool_by_name("vcvars");
|
||||
fs::path bat = conf().tool().get("vcvars");
|
||||
|
||||
if (conf::dry())
|
||||
{
|
||||
@@ -1019,7 +1024,7 @@ fs::path find_iscc()
|
||||
if (!tasks[0]->enabled())
|
||||
return {};
|
||||
|
||||
auto iscc = conf::tool_by_name("iscc");
|
||||
auto iscc = conf().tool().get("iscc");
|
||||
if (iscc.is_absolute())
|
||||
{
|
||||
if (!fs::exists(iscc))
|
||||
@@ -1290,6 +1295,11 @@ void conf_global::set_dry(std::string_view s)
|
||||
g_dry = bool_from_string(s);
|
||||
}
|
||||
|
||||
conf_tools::conf_tools()
|
||||
: conf_section("tools")
|
||||
{
|
||||
}
|
||||
|
||||
conf_transifex::conf_transifex()
|
||||
: conf_section("transifex")
|
||||
{
|
||||
|
||||
+53
-18
@@ -3,25 +3,29 @@
|
||||
namespace mob
|
||||
{
|
||||
|
||||
class conf_section;
|
||||
class conf_global;
|
||||
class conf_prebuilt;
|
||||
class conf_task;
|
||||
class conf_tools;
|
||||
class conf_transifex;
|
||||
class conf_prebuilt;
|
||||
class conf_versions;
|
||||
class conf_paths;
|
||||
|
||||
class conf
|
||||
{
|
||||
// temp
|
||||
friend class conf_section;
|
||||
friend class conf_global;
|
||||
friend class conf_prebuilt;
|
||||
friend class conf_task;
|
||||
friend class conf_tools;
|
||||
friend class conf_transifex;
|
||||
friend class conf_prebuilt;
|
||||
friend class conf_versions;
|
||||
friend class conf_paths;
|
||||
|
||||
public:
|
||||
conf_global global();
|
||||
conf_task task(const std::vector<std::string>& names);
|
||||
conf_tools tool();
|
||||
conf_transifex transifex();
|
||||
conf_prebuilt prebuilt();
|
||||
conf_versions version();
|
||||
@@ -31,14 +35,6 @@ public:
|
||||
//
|
||||
static bool dry();
|
||||
|
||||
static std::string task_option_by_name(
|
||||
const std::vector<std::string>& task_names, std::string_view name);
|
||||
|
||||
static bool bool_task_option_by_name(
|
||||
const std::vector<std::string>& task_names, std::string_view name);
|
||||
|
||||
static fs::path tool_by_name(std::string_view name);
|
||||
|
||||
|
||||
// only in conf.cpp
|
||||
static std::string get_global(
|
||||
@@ -84,6 +80,12 @@ private:
|
||||
|
||||
static std::string global_by_name(std::string_view name);
|
||||
static bool bool_global_by_name(std::string_view name);
|
||||
|
||||
static std::string task_option_by_name(
|
||||
const std::vector<std::string>& task_names, std::string_view name);
|
||||
|
||||
static bool bool_task_option_by_name(
|
||||
const std::vector<std::string>& task_names, std::string_view name);
|
||||
};
|
||||
|
||||
|
||||
@@ -105,10 +107,11 @@ fs::path make_temp_file();
|
||||
|
||||
|
||||
|
||||
template <class DefaultType>
|
||||
class conf_section
|
||||
{
|
||||
public:
|
||||
std::string get(std::string_view key) const
|
||||
DefaultType get(std::string_view key) const
|
||||
{
|
||||
return conf::get_global(name_, key);
|
||||
}
|
||||
@@ -144,7 +147,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class conf_global : public conf_section
|
||||
class conf_global : public conf_section<std::string>
|
||||
{
|
||||
public:
|
||||
conf_global();
|
||||
@@ -174,19 +177,51 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class conf_transifex : public conf_section
|
||||
class conf_task
|
||||
{
|
||||
public:
|
||||
conf_task(std::vector<std::string> names)
|
||||
: names_(std::move(names))
|
||||
{
|
||||
}
|
||||
|
||||
std::string get(std::string_view key) const
|
||||
{
|
||||
return conf::task_option_by_name(names_, key);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T get(std::string_view key) const;
|
||||
|
||||
template <>
|
||||
bool get<bool>(std::string_view key) const
|
||||
{
|
||||
return conf::bool_task_option_by_name(names_, key);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> names_;
|
||||
};
|
||||
|
||||
class conf_tools : public conf_section<fs::path>
|
||||
{
|
||||
public:
|
||||
conf_tools();
|
||||
};
|
||||
|
||||
class conf_transifex : public conf_section<std::string>
|
||||
{
|
||||
public:
|
||||
conf_transifex();
|
||||
};
|
||||
|
||||
class conf_versions : public conf_section
|
||||
class conf_versions : public conf_section<std::string>
|
||||
{
|
||||
public:
|
||||
conf_versions();
|
||||
};
|
||||
|
||||
class conf_prebuilt : public conf_section
|
||||
class conf_prebuilt : public conf_section<std::string>
|
||||
{
|
||||
public:
|
||||
conf_prebuilt();
|
||||
@@ -198,7 +233,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class conf_paths : public conf_section
|
||||
class conf_paths : public conf_section<fs::path>
|
||||
{
|
||||
public:
|
||||
conf_paths();
|
||||
|
||||
+15
-15
@@ -259,72 +259,72 @@ task_conf_holder::task_conf_holder(const task& t)
|
||||
|
||||
std::string task_conf_holder::mo_org() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "mo_org");
|
||||
return conf().task(task_.names()).get("mo_org");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::mo_branch() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "mo_branch");
|
||||
return conf().task(task_.names()).get("mo_branch");
|
||||
}
|
||||
|
||||
bool task_conf_holder::no_pull() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "no_pull");
|
||||
return conf().task(task_.names()).get<bool>("no_pull");
|
||||
}
|
||||
|
||||
bool task_conf_holder::revert_ts() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "revert_ts");
|
||||
return conf().task(task_.names()).get<bool>("revert_ts");
|
||||
}
|
||||
|
||||
bool task_conf_holder::ignore_ts()const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "ignore_ts");
|
||||
return conf().task(task_.names()).get<bool>("ignore_ts");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::git_url_prefix() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "git_url_prefix");
|
||||
return conf().task(task_.names()).get("git_url_prefix");
|
||||
}
|
||||
|
||||
bool task_conf_holder::git_shallow() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "git_shallow");
|
||||
return conf().task(task_.names()).get<bool>("git_shallow");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::git_user() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "git_username");
|
||||
return conf().task(task_.names()).get("git_username");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::git_email() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "git_email");
|
||||
return conf().task(task_.names()).get("git_email");
|
||||
}
|
||||
|
||||
bool task_conf_holder::set_origin_remote() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "set_origin_remote");
|
||||
return conf().task(task_.names()).get<bool>("set_origin_remote");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::remote_org() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "remote_org");
|
||||
return conf().task(task_.names()).get("remote_org");
|
||||
}
|
||||
|
||||
std::string task_conf_holder::remote_key() const
|
||||
{
|
||||
return conf::task_option_by_name(task_.names(), "remote_key");
|
||||
return conf().task(task_.names()).get("remote_key");
|
||||
}
|
||||
|
||||
bool task_conf_holder::remote_no_push_upstream() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "remote_no_push_upstream");
|
||||
return conf().task(task_.names()).get<bool>("remote_no_push_upstream");
|
||||
}
|
||||
|
||||
bool task_conf_holder::remote_push_default_origin() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(task_.names(), "remote_push_default_origin");
|
||||
return conf().task(task_.names()).get<bool>("remote_push_default_origin");
|
||||
}
|
||||
|
||||
git task_conf_holder::make_git(git::ops o) const
|
||||
@@ -396,7 +396,7 @@ task::~task()
|
||||
|
||||
bool task::enabled() const
|
||||
{
|
||||
return conf::bool_task_option_by_name(names(), "enabled");
|
||||
return conf().task(names()).get<bool>("enabled");
|
||||
}
|
||||
|
||||
bool task::is_super() const
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ cmake::cmake(ops o)
|
||||
|
||||
fs::path cmake::binary()
|
||||
{
|
||||
return conf::tool_by_name("cmake");
|
||||
return conf().tool().get("cmake");
|
||||
}
|
||||
|
||||
cmake& cmake::generator(generators g)
|
||||
|
||||
@@ -12,7 +12,7 @@ extractor::extractor()
|
||||
|
||||
fs::path extractor::binary()
|
||||
{
|
||||
return conf::tool_by_name("sevenz");
|
||||
return conf().tool().get("sevenz");
|
||||
}
|
||||
|
||||
extractor& extractor::file(const fs::path& file)
|
||||
|
||||
+1
-1
@@ -202,7 +202,7 @@ std::string git::current_branch()
|
||||
|
||||
fs::path git::binary()
|
||||
{
|
||||
return conf::tool_by_name("git");
|
||||
return conf().tool().get("git");
|
||||
}
|
||||
|
||||
git& git::url(const mob::url& u)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ jom::jom()
|
||||
|
||||
fs::path jom::binary()
|
||||
{
|
||||
return conf::tool_by_name("jom");
|
||||
return conf().tool().get("jom");
|
||||
}
|
||||
|
||||
jom& jom::path(const fs::path& p)
|
||||
|
||||
@@ -24,7 +24,7 @@ msbuild::msbuild(ops o) :
|
||||
|
||||
fs::path msbuild::binary()
|
||||
{
|
||||
return conf::tool_by_name("msbuild");
|
||||
return conf().tool().get("msbuild");
|
||||
}
|
||||
|
||||
msbuild& msbuild::solution(const fs::path& sln)
|
||||
|
||||
@@ -13,7 +13,7 @@ patcher::patcher()
|
||||
|
||||
fs::path patcher::binary()
|
||||
{
|
||||
return conf::tool_by_name("patch");
|
||||
return conf().tool().get("patch");
|
||||
}
|
||||
|
||||
patcher& patcher::task(const std::string& name, bool prebuilt)
|
||||
|
||||
+9
-9
@@ -73,12 +73,12 @@ const context& tool::cx() const
|
||||
|
||||
fs::path perl::binary()
|
||||
{
|
||||
return conf::tool_by_name("perl");
|
||||
return conf().tool().get("perl");
|
||||
}
|
||||
|
||||
fs::path nasm::binary()
|
||||
{
|
||||
return conf::tool_by_name("nasm");
|
||||
return conf().tool().get("nasm");
|
||||
}
|
||||
|
||||
fs::path qt::installation_path()
|
||||
@@ -109,7 +109,7 @@ vs::vs(ops o)
|
||||
|
||||
fs::path vs::devenv_binary()
|
||||
{
|
||||
return conf::tool_by_name("devenv");
|
||||
return conf().tool().get("devenv");
|
||||
}
|
||||
|
||||
fs::path vs::installation_path()
|
||||
@@ -119,12 +119,12 @@ fs::path vs::installation_path()
|
||||
|
||||
fs::path vs::vswhere()
|
||||
{
|
||||
return conf::tool_by_name("vswhere");
|
||||
return conf().tool().get("vswhere");
|
||||
}
|
||||
|
||||
fs::path vs::vcvars()
|
||||
{
|
||||
return conf::tool_by_name("vcvars");
|
||||
return conf().tool().get("vcvars");
|
||||
}
|
||||
|
||||
std::string vs::version()
|
||||
@@ -221,7 +221,7 @@ nuget::nuget(fs::path sln)
|
||||
|
||||
fs::path nuget::binary()
|
||||
{
|
||||
return conf::tool_by_name("nuget");
|
||||
return conf().tool().get("nuget");
|
||||
}
|
||||
|
||||
void nuget::do_run()
|
||||
@@ -421,7 +421,7 @@ transifex::transifex(ops o) :
|
||||
|
||||
fs::path transifex::binary()
|
||||
{
|
||||
return conf::tool_by_name("tx");
|
||||
return conf().tool().get("tx");
|
||||
}
|
||||
|
||||
transifex& transifex::root(const fs::path& p)
|
||||
@@ -549,7 +549,7 @@ lrelease::lrelease()
|
||||
|
||||
fs::path lrelease::binary()
|
||||
{
|
||||
return conf::tool_by_name("lrelease");
|
||||
return conf().tool().get("lrelease");
|
||||
}
|
||||
|
||||
lrelease& lrelease::project(const std::string& name)
|
||||
@@ -625,7 +625,7 @@ iscc::iscc(fs::path iss)
|
||||
|
||||
fs::path iscc::binary()
|
||||
{
|
||||
return conf::tool_by_name("iscc");
|
||||
return conf().tool().get("iscc");
|
||||
}
|
||||
|
||||
iscc& iscc::iss(const fs::path& p)
|
||||
|
||||
Reference in New Issue
Block a user