diff --git a/snag.json b/snag.json index d8f176b..0cdee67 100644 --- a/snag.json +++ b/snag.json @@ -10,5 +10,15 @@ "postsnag": [ "/usr/bin/ls", "/usr/local/bin/script.sh" - ] + ], + "rules": { + "tracking": [ + "/etc/*.conf" + ], + "ignore": [ + "/usr/exit/.gitignore", + "/usr/exit/dd", + "/file1" + ] + } } diff --git a/source/snag/config/config.d b/source/snag/config/config.d index 75de340..635cc6d 100644 --- a/source/snag/config/config.d +++ b/source/snag/config/config.d @@ -5,6 +5,8 @@ import std.file; import std.path; import std.string; import snag.lib; +import std.algorithm; +import std.array; import snag.config.exception; @@ -13,6 +15,8 @@ class SnagConfig { private string _project; private string _email; private string _author; + private string[] _tracking; + private string[] _ignore; this(string configFile) { string jsonText; @@ -93,10 +97,34 @@ class SnagConfig { throw new SnagConfigException( "The \"author\" parameter must contain an author name" ); + + if ("rules" in jsonData) { + if (jsonData["rules"].type != JSONType.object) + throw new SnagConfigException( + "The \"rules\" parameter must be an object" + ); + auto rules = jsonData["rules"]; + if ("tracking" in rules) { + if (rules["tracking"].type != JSONType.array) + throw new SnagConfigException( + "The \"tracking\" parameter must be an array containing a set of paths to tracked files" + ); + _tracking = rules["tracking"].array.map!(item => item.str).array; + } + if ("ignore" in rules) { + if (rules["ignore"].type != JSONType.array) + throw new SnagConfigException( + "The \"ignore\" parameter must contain a gitignore rule" + ); + _ignore = rules["ignore"].array.map!(item => item.str).array; + } + } } @property string git() const { return _git; } @property string project() const { return _project; } @property string email() const { return _email; } @property string author() const { return _author; } + @property const(string[]) tracking() const { return _tracking; } + @property const(string[]) ignore() const { return _ignore; } }