mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
aliases
This commit is contained in:
@@ -38,13 +38,14 @@ git_shallow = false
|
||||
git_shallow = false
|
||||
|
||||
[installer:task]
|
||||
enabled = false
|
||||
git_shallow = false
|
||||
|
||||
[translations:task]
|
||||
enabled = false
|
||||
|
||||
[installer:task]
|
||||
enabled = false
|
||||
[aliases]
|
||||
plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_*
|
||||
|
||||
[tools]
|
||||
sevenz = 7z.exe
|
||||
|
||||
+34
-25
@@ -184,23 +184,7 @@ void command::set_task_enabled_flags(const std::vector<std::string>& names)
|
||||
bool failed = false;
|
||||
|
||||
for (auto&& pattern : names)
|
||||
{
|
||||
const auto tasks = find_tasks(pattern);
|
||||
|
||||
if (tasks.empty())
|
||||
{
|
||||
u8cout << "no task matching '" << pattern<< "' found\n";
|
||||
|
||||
u8cout << "valid tasks:\n";
|
||||
for (auto&& t : get_all_tasks())
|
||||
u8cout << " - " << join(t->names(), ", ") << "\n";
|
||||
|
||||
failed = true;
|
||||
}
|
||||
|
||||
for (auto&& t : tasks)
|
||||
common.options.push_back(t->name() + ":task/enabled=true");
|
||||
}
|
||||
common.options.push_back(pattern + ":task/enabled=true");
|
||||
|
||||
if (failed)
|
||||
throw bailed();
|
||||
@@ -598,6 +582,9 @@ clipp::group list_command::do_group()
|
||||
(clipp::option("-a", "--all") >> all_)
|
||||
% "shows all the tasks, including pseudo parallel tasks",
|
||||
|
||||
(clipp::option("-i", "--aliases") >> aliases_)
|
||||
% "shows only aliases",
|
||||
|
||||
(clipp::opt_values(
|
||||
clipp::match::prefix_not("-"), "task", tasks_))
|
||||
% "with -a; when given, acts like the tasks given to `build` and "
|
||||
@@ -607,20 +594,31 @@ clipp::group list_command::do_group()
|
||||
|
||||
int list_command::do_run()
|
||||
{
|
||||
if (all_)
|
||||
if (aliases_)
|
||||
{
|
||||
if (!tasks_.empty())
|
||||
set_task_enabled_flags(tasks_);
|
||||
|
||||
load_options();
|
||||
dump(get_top_level_tasks(), 0);
|
||||
dump_aliases();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto&& t : get_all_tasks())
|
||||
u8cout << " - " << join(t->names(), ", ") << "\n";
|
||||
if (all_)
|
||||
{
|
||||
if (!tasks_.empty())
|
||||
set_task_enabled_flags(tasks_);
|
||||
|
||||
load_options();
|
||||
dump(get_top_level_tasks(), 0);
|
||||
|
||||
u8cout << "\n\naliases:\n";
|
||||
dump_aliases();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto&& t : get_all_tasks())
|
||||
u8cout << " - " << join(t->names(), ", ") << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -641,6 +639,17 @@ void list_command::dump(const std::vector<task*>& v, std::size_t indent) const
|
||||
}
|
||||
}
|
||||
|
||||
void list_command::dump_aliases() const
|
||||
{
|
||||
const auto v = get_all_aliases();
|
||||
if (v.empty())
|
||||
return;
|
||||
|
||||
for (auto&& [k, patterns] : v)
|
||||
u8cout << " - " << k << ": " << join(patterns, ", ") << "\n";
|
||||
}
|
||||
|
||||
|
||||
std::string list_command::do_doc()
|
||||
{
|
||||
return
|
||||
|
||||
@@ -160,9 +160,15 @@ protected:
|
||||
|
||||
private:
|
||||
bool all_ = false;
|
||||
bool aliases_ = false;
|
||||
std::vector<std::string> tasks_;
|
||||
|
||||
void dump(const std::vector<task*>& v, std::size_t indent) const;
|
||||
|
||||
void dump_tasks(
|
||||
const std::vector<task*>& v, std::size_t indent, bool recurse) const;
|
||||
|
||||
void dump_aliases() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+5
-1
@@ -767,7 +767,11 @@ void parse_section(
|
||||
if (k.empty())
|
||||
ini_error(ini, i, "bad line '" + line + "'");
|
||||
|
||||
if (task.empty())
|
||||
if (section == "aliases")
|
||||
{
|
||||
add_alias(k, split_quoted(v, " "));
|
||||
}
|
||||
else if (task.empty())
|
||||
{
|
||||
if (add)
|
||||
conf::add_global(section, k, v);
|
||||
|
||||
+56
-8
@@ -12,6 +12,7 @@ class interrupted {};
|
||||
static std::vector<std::unique_ptr<task>> g_tasks;
|
||||
static std::vector<task*> g_all_tasks;
|
||||
static std::atomic<bool> g_interrupt = false;
|
||||
static alias_map g_aliases;
|
||||
std::mutex task::interrupt_mutex_;
|
||||
|
||||
|
||||
@@ -40,7 +41,7 @@ std::vector<task*> get_top_level_tasks()
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<task*> find_tasks(const std::string& pattern)
|
||||
std::vector<task*> find_tasks_by_pattern(const std::string& pattern)
|
||||
{
|
||||
std::vector<task*> tasks;
|
||||
|
||||
@@ -66,21 +67,50 @@ std::vector<task*> find_tasks(const std::string& pattern)
|
||||
return tasks;
|
||||
}
|
||||
|
||||
task* find_task(const std::string& pattern)
|
||||
std::vector<task*> find_tasks_by_alias(const std::string& pattern)
|
||||
{
|
||||
std::vector<task*> v;
|
||||
|
||||
auto itor = g_aliases.find(pattern);
|
||||
if (itor == g_aliases.end())
|
||||
return v;
|
||||
|
||||
for (auto&& a : itor->second)
|
||||
{
|
||||
const auto temp = find_tasks_by_pattern(a);
|
||||
v.insert(v.end(), temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<task*> find_tasks(const std::string& pattern)
|
||||
{
|
||||
std::vector<task*> tasks;
|
||||
|
||||
for (auto&& t : g_all_tasks)
|
||||
{
|
||||
if (pattern == "super" && t->is_super())
|
||||
return t;
|
||||
|
||||
for (auto&& n : t->names())
|
||||
{
|
||||
if (mob::glob_match(pattern, n))
|
||||
return t;
|
||||
tasks.push_back(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto&& n : t->names())
|
||||
{
|
||||
if (mob::glob_match(pattern, n))
|
||||
{
|
||||
tasks.push_back(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
if (tasks.empty())
|
||||
tasks = find_tasks_by_alias(pattern);
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
void run_all_tasks()
|
||||
@@ -132,6 +162,24 @@ bool is_super_task(const std::string& name)
|
||||
return false;
|
||||
}
|
||||
|
||||
void add_alias(std::string name, std::vector<std::string> names)
|
||||
{
|
||||
auto itor = g_aliases.find(name);
|
||||
if (itor != g_aliases.end())
|
||||
{
|
||||
gcx().warning(context::generic, "alias {} already exists", name);
|
||||
return;
|
||||
}
|
||||
|
||||
g_aliases.emplace(std::move(name), std::move(names));
|
||||
}
|
||||
|
||||
const alias_map& get_all_aliases()
|
||||
{
|
||||
return g_aliases;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string to_string(task::clean c)
|
||||
{
|
||||
|
||||
+4
-1
@@ -24,11 +24,14 @@ Task& add_task(Args&&... args)
|
||||
void run_all_tasks();
|
||||
bool is_super_task(const std::string& name);
|
||||
std::vector<task*> find_tasks(const std::string& pattern);
|
||||
task* find_task(const std::string& pattern);
|
||||
|
||||
std::vector<task*> get_all_tasks();
|
||||
std::vector<task*> get_top_level_tasks();
|
||||
|
||||
using alias_map = std::map<std::string, std::vector<std::string>>;
|
||||
void add_alias(std::string name, std::vector<std::string> patterns);
|
||||
const alias_map& get_all_aliases();
|
||||
|
||||
|
||||
class task_conf_holder
|
||||
{
|
||||
|
||||
@@ -383,6 +383,55 @@ std::vector<std::string> split(const std::string& s, const std::string& seps)
|
||||
return v;
|
||||
}
|
||||
|
||||
std::vector<std::string> split_quoted(const std::string& s, const std::string& seps)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
bool q = false;
|
||||
std::string token;
|
||||
|
||||
for (std::size_t i=0; i<s.size(); ++i)
|
||||
{
|
||||
if (seps.find(s[i]) != std::string::npos)
|
||||
{
|
||||
if (q)
|
||||
{
|
||||
token += s[i];
|
||||
}
|
||||
else if (!token.empty())
|
||||
{
|
||||
v.push_back(token);
|
||||
token = "";
|
||||
}
|
||||
}
|
||||
else if (s[i] == '"')
|
||||
{
|
||||
if (q)
|
||||
{
|
||||
q = false;
|
||||
|
||||
if (!token.empty())
|
||||
{
|
||||
v.push_back(token);
|
||||
token = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
q = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
token += s[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!token.empty())
|
||||
v.push_back(token);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void trim_impl(std::basic_string<C>& s, std::basic_string_view<C> what)
|
||||
{
|
||||
|
||||
+2
-1
@@ -336,7 +336,8 @@ T join(const std::vector<T>& v, const Sep& sep)
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& s, const std::string& sep);
|
||||
std::vector<std::string> split(const std::string& s, const std::string& seps);
|
||||
std::vector<std::string> split_quoted(const std::string& s, const std::string& seps);
|
||||
|
||||
std::string pad_right(std::string s, std::size_t n, char c=' ');
|
||||
std::string pad_left(std::string s, std::size_t n, char c=' ');
|
||||
|
||||
Reference in New Issue
Block a user