-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (48 loc) · 3.13 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (48 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.CommandLine;
namespace XmlSort {
internal static class Program {
private static async Task<int> Main(string[] args) {
var debugOption = new Option<bool>("--debug") { Description = "Sortiert ohne die Dateien zurückzuschreiben. --remove Ausdrücke werden getestet. Vorgabe: false" };
var removeOption = new Option<string?>("--remove") { Description = "Semikolon-getrennte Liste von XPath-Ausdrücken; passende Elemente werden entfernt. Bsp: //IAttribute[ident='crb_Display']" };
var sortOption = new Option<string?>("--sort") { Description = "Semikolon-getrennte Liste von XPath-Ausdrücken, welche zur Ermittlung der Sortierkriterien zusätzlich evaluiert werden. Bsp: ./ident;./address/number" };
var ignoreNamespacesOption = new Option<bool>("--ignoreNameSpaces") { Description = "Legt fest, dass Namespaces ignoriert werden. . Vorgabe: true", DefaultValueFactory = (_) => true };
var fileArgument = new Argument<FileInfo>("path") {
Description = "Pfad zu einer vorhandenen XML-Datei"
};
fileArgument.AcceptExistingOnly();
var fileCommand = new Command("file", "Sortiert eine einzelne XML-Datei") { fileArgument };
fileCommand.SetAction(result => {
var file = result.GetValue(fileArgument)!;
XmlSorterOptions opt = new() {
Debug = result.GetValue(debugOption),
RemoveExpressions = result.GetValue(removeOption)?.Split(';') ?? Array.Empty<string>(),
SortExpressions = result.GetValue(sortOption)?.Split(';') ?? Array.Empty<string>(),
IgnoreNameSpaces = result.GetValue(ignoreNamespacesOption),
};
new XmlSorter(opt).SortFile(file);
});
var dirArgument = new Argument<DirectoryInfo>("path") {
Description = "Pfad zu einem vorhandenen Verzeichnis mit XML-Dateien"
};
dirArgument.AcceptExistingOnly();
var dirCommand = new Command("dir", "Sortiert alle XML-Dateien in einem Verzeichnis") { dirArgument };
dirCommand.SetAction(result => {
var dir = result.GetValue(dirArgument)!;
XmlSorterOptions opt = new() {
Debug = result.GetValue(debugOption),
RemoveExpressions = result.GetValue(removeOption)?.Split(';') ?? Array.Empty<string>(),
SortExpressions = result.GetValue(sortOption)?.Split(';') ?? Array.Empty<string>(),
IgnoreNameSpaces = result.GetValue(ignoreNamespacesOption),
};
new XmlSorter(opt).SortDirectory(dir);
});
var rootCommand = new RootCommand("XmlSort – Sortiert Attribute und Elemente in XML-Dateien") { fileCommand, dirCommand };
rootCommand.Add(debugOption);
rootCommand.Add(removeOption);
rootCommand.Add(sortOption);
rootCommand.Add(ignoreNamespacesOption);
var parseResult = rootCommand.Parse(args);
return await parseResult.InvokeAsync();
}
}
}