This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgramBase.cs
52 lines (42 loc) · 1.56 KB
/
ProgramBase.cs
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
using System.Security.Cryptography;
namespace LogParserApp;
public class ProgramBase
{
private static readonly char[] _trimChars = ['"', ' '];
public static Dictionary<string, List<string>> ParseArguments(string[] args)
{
var settings = new Dictionary<string, List<string>>();
string? currentKey = null;
foreach (var arg in args)
{
if (arg.StartsWith('-'))
{
currentKey = arg.TrimStart('-').ToLower();
settings[currentKey] = [];
}
else if (currentKey != null)
{
settings[currentKey].Add(arg.Trim(_trimChars));
}
}
// Handle filetypes and postprocess options specified as a comma-separated list
if (settings.TryGetValue("filetype", out List<string>? value1))
{
settings["filetype"] = value1.SelectMany(f => f.Split(','))
.Select(f => f.Trim())
.ToList();
}
if (settings.TryGetValue("postprocess", out List<string>? value2) && value2.Count > 1)
{
// Additional argument for archive path if postprocess is 'archive'
settings["archivepath"] = [value2[1]];
settings["postprocess"] = [value2[0]];
}
// Add support for the 'after' argument
if (settings.TryGetValue("after", out List<string>? value3) && value3.Count == 0)
{
settings["after"] = ["true"]; // Indicate that the 'after' argument is present
}
return settings;
}
}