diff --git a/src/tasks/task.cpp b/src/tasks/task.cpp index 0f6dd98..24fef01 100644 --- a/src/tasks/task.cpp +++ b/src/tasks/task.cpp @@ -35,22 +35,30 @@ void list_tasks(bool err) } } -task* find_task(const std::string& name) +std::vector find_tasks(const std::string& pattern) { + std::vector 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 tasks) @@ -110,7 +118,7 @@ void gather_super_tasks(std::vector& tasks, std::set& seen) void run_task(const std::string& name) { - run_tasks({find_task(name)}); + run_tasks({name}); } void run_tasks(const std::vector& names) @@ -133,12 +141,12 @@ void run_tasks(const std::vector& 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); + } } } } diff --git a/src/utility.cpp b/src/utility.cpp index af47441..f3dd137 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -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) { diff --git a/src/utility.h b/src/utility.h index 8ba9223..4fd6de4 100644 --- a/src/utility.h +++ b/src/utility.h @@ -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);