Rework commandline arguments && Add Exceptions
This commit is contained in:
parent
04048c4cb9
commit
888df20cc9
@ -7,9 +7,12 @@
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "determinePacmanCacheDirectory":
|
||||
Pacserver.determinePacmanCacheDirectory();
|
||||
Console.WriteLine(Pacserver.determinePacmanCacheDirectory());
|
||||
break;
|
||||
default:
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||
Console.ResetColor();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
|
||||
public class Pacserver {
|
||||
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanCacheDirectory() {
|
||||
// string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
|
||||
string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
|
||||
|
||||
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||
string? line;
|
||||
@ -13,7 +13,11 @@ public class Pacserver {
|
||||
Match match = regex.Match(line);
|
||||
if (match.Success) {
|
||||
pacmanCacheDirectory = match.ToString();
|
||||
} else {
|
||||
throw new Exception("Could not determine where pacman cache is! Would normally be found here " + defaultPacmanCacheDirectory);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Pacman config has no CacheDir specified!");
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user