Rework commandline arguments && Add Exceptions
This commit is contained in:
parent
04048c4cb9
commit
888df20cc9
@ -7,9 +7,12 @@
|
|||||||
} else {
|
} else {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "determinePacmanCacheDirectory":
|
case "determinePacmanCacheDirectory":
|
||||||
Pacserver.determinePacmanCacheDirectory();
|
Console.WriteLine(Pacserver.determinePacmanCacheDirectory());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||||
|
Console.ResetColor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using System.Text.RegularExpressions;
|
|||||||
public class Pacserver {
|
public class Pacserver {
|
||||||
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||||
public static string determinePacmanCacheDirectory() {
|
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
|
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||||
string? line;
|
string? line;
|
||||||
@ -13,7 +13,11 @@ public class Pacserver {
|
|||||||
Match match = regex.Match(line);
|
Match match = regex.Match(line);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
pacmanCacheDirectory = match.ToString();
|
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();
|
file.Close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user