Добавлено чтение из конфигурационного файла набора правил для отслеживания файлов
This commit is contained in:
parent
5797e83f07
commit
aa4260cdb9
2 changed files with 39 additions and 1 deletions
12
snag.json
12
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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue