Browse Source

Manager: Add target filtering to Dotfile::list()

master
Riyyi 3 years ago
parent
commit
f8ccfe79b8
  1. 16
      src/dotfile.cpp
  2. 3
      src/dotfile.h

16
src/dotfile.cpp

@ -26,7 +26,7 @@ Dotfile::~Dotfile()
// -----------------------------------------
void Dotfile::list()
void Dotfile::list(const std::vector<std::string>& targets)
{
if (s_workingDirectory.empty()) {
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)) {
continue;
}
if (!targets.empty() && !include(path.path().string(), targets)) {
continue;
}
printf("%s\n", path.path().c_str() + workingDirectory);
}
}
@ -72,4 +75,15 @@ bool Dotfile::filter(const std::filesystem::path& path)
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

3
src/dotfile.h

@ -29,13 +29,14 @@ public:
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 setExcludePaths(const std::vector<ExcludePath>& excludePaths) { s_excludePaths = excludePaths; }
private:
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::filesystem::path s_workingDirectory;

Loading…
Cancel
Save