mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
Allow usage of glob-like string for task names.
This commit is contained in:
+22
-14
@@ -35,22 +35,30 @@ void list_tasks(bool err)
|
||||
}
|
||||
}
|
||||
|
||||
task* find_task(const std::string& name)
|
||||
std::vector<task*> find_tasks(const std::string& pattern)
|
||||
{
|
||||
std::vector<task*> tasks;
|
||||
for (auto&& t : g_all_tasks)
|
||||
{
|
||||
for (auto&& n : t->names())
|
||||
{
|
||||
if (n == name)
|
||||
return t;
|
||||
if (mob::glob_match(pattern, n)) {
|
||||
tasks.push_back(t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u8cout << "task " << name << " not found\n";
|
||||
u8cout << "valid tasks:\n";
|
||||
list_tasks(true);
|
||||
if (tasks.empty()) {
|
||||
|
||||
throw bailed("");
|
||||
u8cout << "no task matching " << pattern << " found\n";
|
||||
u8cout << "valid tasks:\n";
|
||||
list_tasks(true);
|
||||
|
||||
throw bailed("");
|
||||
}
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
void run_tasks(const std::vector<task*> tasks)
|
||||
@@ -110,7 +118,7 @@ void gather_super_tasks(std::vector<task*>& tasks, std::set<task*>& seen)
|
||||
|
||||
void run_task(const std::string& name)
|
||||
{
|
||||
run_tasks({find_task(name)});
|
||||
run_tasks({name});
|
||||
}
|
||||
|
||||
void run_tasks(const std::vector<std::string>& names)
|
||||
@@ -133,12 +141,12 @@ void run_tasks(const std::vector<std::string>& names)
|
||||
}
|
||||
else
|
||||
{
|
||||
auto* t = find_task(name);
|
||||
|
||||
if (!seen.contains(t))
|
||||
{
|
||||
tasks.push_back(t);
|
||||
seen.insert(t);
|
||||
for (auto* t : find_tasks(name)) {
|
||||
if (!seen.contains(t))
|
||||
{
|
||||
tasks.push_back(t);
|
||||
seen.insert(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +318,11 @@ url make_appveyor_artifact_url(
|
||||
project + "/artifacts/" + filename + "?job=Platform:%20" + arch_s;
|
||||
}
|
||||
|
||||
bool glob_match(const std::string& pattern, const std::string& s)
|
||||
{
|
||||
return std::regex_match(s, std::regex{ replace_all(pattern, "*", ".*") });
|
||||
}
|
||||
|
||||
std::string replace_all(
|
||||
std::string s, const std::string& from, const std::string& to)
|
||||
{
|
||||
|
||||
@@ -294,6 +294,8 @@ url make_prebuilt_url(const std::string& filename);
|
||||
url make_appveyor_artifact_url(
|
||||
arch a, const std::string& project, const std::string& filename);
|
||||
|
||||
bool glob_match(const std::string& pattern, const std::string& s);
|
||||
|
||||
std::string replace_all(
|
||||
std::string s, const std::string& from, const std::string& to);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user