From 888df20cc992e6fb694e7838b87850ed54daffc2 Mon Sep 17 00:00:00 2001 From: ProfessionalUwU Date: Sat, 3 Jun 2023 14:50:13 +0200 Subject: [PATCH] Rework commandline arguments && Add Exceptions --- Program.cs | 5 ++++- pacserver.cs | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index b4a8c8c..bb81872 100644 --- a/Program.cs +++ b/Program.cs @@ -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; } } diff --git a/pacserver.cs b/pacserver.cs index 1dbf462..5ebad7e 100644 --- a/pacserver.cs +++ b/pacserver.cs @@ -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();