Everywhere: Change exclude path configuration formatting
This commit is contained in:
+19
-13
@@ -31,23 +31,29 @@ the config file is searched recursively. \\
|
||||
|
||||
**** Exclude paths
|
||||
|
||||
Everything in this list will get excluded when pushing config files from the working directory to the system. \\
|
||||
Currently three types of file matching are supported:
|
||||
Everything in this list will get excluded when pulling/pushing config files from the working directory. \\
|
||||
Currently two types of file matching are supported:
|
||||
|
||||
- ~file~ full name of the file matches
|
||||
- ~directory~ full name of the directory matches
|
||||
- ~endsWith~ end of the path matches
|
||||
- ~literal~ matches a file or directory literally
|
||||
- ~wildcard~ the asterisk matches zero or more characters
|
||||
|
||||
These behave similarly to a ~.gitignore~ pattern.
|
||||
|
||||
- If the pattern starts with a slash, it matches files and directories in the working directory root only.
|
||||
- If the pattern doesn’t start with a slash, it matches files and directories in any directory or subdirectory.
|
||||
- If the pattern ends with a slash, it matches only directories. When a directory is ignored, \\
|
||||
all of its files and subdirectories are also ignored.
|
||||
|
||||
The excluded paths from the example config:
|
||||
#+BEGIN_SRC javascript
|
||||
"excludePaths" : {
|
||||
".git": "directory",
|
||||
".md": "endsWith",
|
||||
"manafiles.json": "endsWith",
|
||||
"packages": "file",
|
||||
"README.org": "endsWith",
|
||||
"screenshot.png": "file"
|
||||
}
|
||||
"excludePaths" : [
|
||||
".git/",
|
||||
"*.md",
|
||||
"manafiles.json",
|
||||
"packages",
|
||||
"README.org",
|
||||
"screenshot.png"
|
||||
]
|
||||
#+END_SRC
|
||||
|
||||
**** System config files
|
||||
|
||||
+8
-8
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"excludePaths" : {
|
||||
".git": "directory",
|
||||
".md": "endsWith",
|
||||
"manafiles.json": "endsWith",
|
||||
"packages": "file",
|
||||
"README.org": "endsWith",
|
||||
"screenshot.png": "file"
|
||||
},
|
||||
"excludePaths" : [
|
||||
".git/",
|
||||
"*.md",
|
||||
"manafiles.json",
|
||||
"packages",
|
||||
"README.org",
|
||||
"screenshot.png"
|
||||
],
|
||||
"systemDirectories": [
|
||||
"/boot",
|
||||
"/etc",
|
||||
|
||||
@@ -89,12 +89,4 @@ void from_json(const nlohmann::json& object, Settings& settings)
|
||||
if (object.find("systemDirectories") != object.end()) {
|
||||
object.at("systemDirectories").get_to(settings.systemDirectories);
|
||||
}
|
||||
|
||||
// Check for correct exclude type values
|
||||
for (const auto& path : settings.excludePaths) {
|
||||
if (path.second != "file" && path.second != "directory" && path.second != "endsWith") {
|
||||
fprintf(stderr, "\033[31;1mConfig:\033[0m invalid exclude type '%s'\n", path.second.c_str());
|
||||
raise(SIGABRT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <filesystem> // path
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -18,12 +17,13 @@
|
||||
#include "util/singleton.h"
|
||||
|
||||
struct Settings {
|
||||
std::map<std::string, std::string> excludePaths {
|
||||
{ ".git", "directory" },
|
||||
{ ".md", "endsWith" },
|
||||
{ "packages", "file" },
|
||||
{ "README.org", "endsWith" },
|
||||
{ "screenshot.png", "file" },
|
||||
std::vector<std::string> excludePaths {
|
||||
".git/",
|
||||
"*.md",
|
||||
"manafiles.json",
|
||||
"packages",
|
||||
"README.org",
|
||||
"screenshot.png",
|
||||
};
|
||||
std::vector<std::filesystem::path> systemDirectories {
|
||||
"/boot",
|
||||
@@ -38,10 +38,10 @@ public:
|
||||
virtual ~Config();
|
||||
|
||||
void setSystemDirectories(const std::vector<std::filesystem::path>& systemDirectories) { m_settings.systemDirectories = systemDirectories; }
|
||||
void setExcludePaths(const std::map<std::string, std::string>& excludePaths) { m_settings.excludePaths = excludePaths; }
|
||||
void setExcludePaths(const std::vector<std::string>& excludePaths) { m_settings.excludePaths = excludePaths; }
|
||||
void setVerbose(bool verbose) { m_verbose = verbose; }
|
||||
|
||||
const std::map<std::string, std::string>& excludePaths() const { return m_settings.excludePaths; }
|
||||
const std::vector<std::string>& excludePaths() const { return m_settings.excludePaths; }
|
||||
const std::vector<std::filesystem::path>& systemDirectories() const { return m_settings.systemDirectories; }
|
||||
|
||||
const std::filesystem::path& workingDirectory() const { return m_workingDirectory; }
|
||||
|
||||
+1
-2
@@ -115,8 +115,7 @@ bool Dotfile::filter(const std::filesystem::directory_entry& path)
|
||||
size_t cutFrom = pathString.find(Config::the().workingDirectory()) == 0 ? Config::the().workingDirectorySize() : 0;
|
||||
pathString = pathString.substr(cutFrom);
|
||||
|
||||
for (const auto& excludePathMapEntry : Config::the().excludePaths()) {
|
||||
const auto& excludePath = excludePathMapEntry.first;
|
||||
for (const auto& excludePath : Config::the().excludePaths()) {
|
||||
|
||||
if (pathString == excludePath) {
|
||||
return true;
|
||||
|
||||
+54
-44
@@ -82,7 +82,7 @@ void removeTestDotfiles(const std::vector<std::string>& files, bool deleteInHome
|
||||
}
|
||||
|
||||
void testDotfileFilters(const std::unordered_map<std::string, bool>& tests,
|
||||
const std::unordered_map<std::string, std::string>& testFilters)
|
||||
const std::vector<std::string>& testFilters)
|
||||
{
|
||||
std::vector<std::string> fileNames;
|
||||
std::vector<std::string> fileContents;
|
||||
@@ -117,8 +117,8 @@ TEST_CASE(DotfilesLiteralIgnoreAllFiles)
|
||||
{ "error.log", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "access.log", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"access.log",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
@@ -133,8 +133,8 @@ TEST_CASE(DotfilesLiteralIgnoreFileInRoot)
|
||||
{ "error.log", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "/access.log", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"/access.log",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
@@ -147,14 +147,15 @@ TEST_CASE(DotfilesLiteralIgnoreDirectories)
|
||||
{ "doc/build", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "build/", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"build/",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllFilesWithExtension) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllFilesWithExtension)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "error.log", true },
|
||||
{ "logs/debug.log", true },
|
||||
@@ -164,14 +165,15 @@ TEST_CASE(DotfilesWildcardIgnoreAllFilesWithExtension) {
|
||||
{ "log.txt", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "*.log", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"*.log",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllFilesInRootWithExtension) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllFilesInRootWithExtension)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "error.log", true },
|
||||
{ "logs/debug.log", false },
|
||||
@@ -181,14 +183,15 @@ TEST_CASE(DotfilesWildcardIgnoreAllFilesInRootWithExtension) {
|
||||
{ "log.txt", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "/*.log", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"/*.log",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreFileWithAllExtensions) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreFileWithAllExtensions)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "README.md", true },
|
||||
{ "doc/README.org", true },
|
||||
@@ -198,14 +201,15 @@ TEST_CASE(DotfilesWildcardIgnoreFileWithAllExtensions) {
|
||||
{ "Config.org", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "README.*", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"README.*",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllWithStartingPattern) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllWithStartingPattern)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "cmake/uninstall.cmake.in", true },
|
||||
{ "cmake/templates/template.cmake.in", true },
|
||||
@@ -214,14 +218,15 @@ TEST_CASE(DotfilesWildcardIgnoreAllWithStartingPattern) {
|
||||
{ "CMakeLists.txt", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "cmake*", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"cmake*",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInRootWithStartingPattern) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInRootWithStartingPattern)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "project-directory/README.org", true },
|
||||
{ "project-directory/build/executable", true },
|
||||
@@ -229,28 +234,30 @@ TEST_CASE(DotfilesWildcardIgnoreAllInRootWithStartingPattern) {
|
||||
{ "doc/project-instructions.txt", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "/project*", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"/project*",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInDirectory) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInDirectory)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "build/x32/executable", true },
|
||||
{ "build/x64/executable", true },
|
||||
{ "build/executable", true },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "build/*", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"build/*",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreFileInSubDirectory) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreFileInSubDirectory)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "build/x32/executable", true },
|
||||
{ "build/x64/executable", true },
|
||||
@@ -259,14 +266,15 @@ TEST_CASE(DotfilesWildcardIgnoreFileInSubDirectory) {
|
||||
{ "build/executable", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "build/*/executable", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"build/*/executable",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInSubDirectory) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllInSubDirectory)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "build/x32/executable", true },
|
||||
{ "build/x64/executable", true },
|
||||
@@ -275,14 +283,15 @@ TEST_CASE(DotfilesWildcardIgnoreAllInSubDirectory) {
|
||||
{ "build/executable", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "build/*/*", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"build/*/*",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesWithStartingPattern) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesWithStartingPattern)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "include/header.h", true },
|
||||
{ "include-dependency/header.h", true },
|
||||
@@ -290,14 +299,15 @@ TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesWithStartingPattern) {
|
||||
{ "src/include/header.h", true },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "include*/", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"include*/",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
}
|
||||
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesInRootWithStartingPattern) {
|
||||
TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesInRootWithStartingPattern)
|
||||
{
|
||||
std::unordered_map<std::string, bool> tests = {
|
||||
{ "include/header.h", true },
|
||||
{ "include-dependency/header.h", true },
|
||||
@@ -305,8 +315,8 @@ TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesInRootWithStartingPattern) {
|
||||
{ "src/include/header.h", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "/include*/", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"/include*/",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
@@ -321,8 +331,8 @@ TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesWithEndingPattern)
|
||||
{ "src/include/header.h", true },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "*include/", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"*include/",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
@@ -337,8 +347,8 @@ TEST_CASE(DotfilesWildcardIgnoreAllDirectoriesInRootWithEndingPattern)
|
||||
{ "src/include/header.h", false },
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, std::string> testFilters = {
|
||||
{ "/*include/", "" },
|
||||
std::vector<std::string> testFilters = {
|
||||
"/*include/",
|
||||
};
|
||||
|
||||
testDotfileFilters(tests, testFilters);
|
||||
@@ -478,9 +488,9 @@ TEST_CASE(PushDotfilesWithExcludePath)
|
||||
createTestDotfiles(fileNames, { "", "", "", "" });
|
||||
|
||||
Config::the().setExcludePaths({
|
||||
{ "__test-file-1", "file" },
|
||||
{ "__subdir/", "directory" },
|
||||
{ "*.test", "endsWith" },
|
||||
"__test-file-1",
|
||||
"__subdir/",
|
||||
"*.test",
|
||||
});
|
||||
Dotfile::the().push(fileNames);
|
||||
Config::the().setExcludePaths({});
|
||||
|
||||
Reference in New Issue
Block a user