Manager: Add target filtering to Dotfile::list()
This commit is contained in:
+15
-1
@@ -26,7 +26,7 @@ Dotfile::~Dotfile()
|
|||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
void Dotfile::list()
|
void Dotfile::list(const std::vector<std::string>& targets)
|
||||||
{
|
{
|
||||||
if (s_workingDirectory.empty()) {
|
if (s_workingDirectory.empty()) {
|
||||||
fprintf(stderr, "\033[31;1mDotfile:\033[0m working directory is unset\n");
|
fprintf(stderr, "\033[31;1mDotfile:\033[0m working directory is unset\n");
|
||||||
@@ -43,6 +43,9 @@ void Dotfile::list()
|
|||||||
if (path.is_directory() || filter(path)) {
|
if (path.is_directory() || filter(path)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!targets.empty() && !include(path.path().string(), targets)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
printf("%s\n", path.path().c_str() + workingDirectory);
|
printf("%s\n", path.path().c_str() + workingDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,4 +75,15 @@ bool Dotfile::filter(const std::filesystem::path& path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Dotfile::include(const std::filesystem::path& path, const std::vector<std::string>& targets)
|
||||||
|
{
|
||||||
|
for (const auto& target : targets) {
|
||||||
|
if (path.string().find(s_workingDirectory / target) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Util
|
} // namespace Util
|
||||||
|
|||||||
+2
-1
@@ -29,13 +29,14 @@ public:
|
|||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void list();
|
static void list(const std::vector<std::string>& targets = {});
|
||||||
|
|
||||||
static void setWorkingDirectory(std::filesystem::path directory) { s_workingDirectory = directory; }
|
static void setWorkingDirectory(std::filesystem::path directory) { s_workingDirectory = directory; }
|
||||||
static void setExcludePaths(const std::vector<ExcludePath>& excludePaths) { s_excludePaths = excludePaths; }
|
static void setExcludePaths(const std::vector<ExcludePath>& excludePaths) { s_excludePaths = excludePaths; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool filter(const std::filesystem::path& path);
|
static bool filter(const std::filesystem::path& path);
|
||||||
|
static bool include(const std::filesystem::path& path, const std::vector<std::string>& targets);
|
||||||
|
|
||||||
static std::vector<ExcludePath> s_excludePaths;
|
static std::vector<ExcludePath> s_excludePaths;
|
||||||
static std::filesystem::path s_workingDirectory;
|
static std::filesystem::path s_workingDirectory;
|
||||||
|
|||||||
Reference in New Issue
Block a user