From 7fbc3d3b497115b4a3c86b7944f5192ffd6733df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Fri, 19 Sep 2025 23:39:30 +0200 Subject: [PATCH] Enforce equals syntax for parser options --- .../Program.cs | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/EvenPerfectBitScanner.ResultsParser/Program.cs b/EvenPerfectBitScanner.ResultsParser/Program.cs index 12e9205..28ba604 100644 --- a/EvenPerfectBitScanner.ResultsParser/Program.cs +++ b/EvenPerfectBitScanner.ResultsParser/Program.cs @@ -180,31 +180,16 @@ internal static class Program value = string.Empty; string current = arguments[index]; int equalsIndex = current.IndexOf('='); - if (equalsIndex > 0) + if (equalsIndex <= 0 || equalsIndex == current.Length - 1) { - option = current[..equalsIndex]; - value = current[(equalsIndex + 1)..]; - index++; - if (value.Length == 0) - { - Console.Error.WriteLine($"Option '{option}' must specify a value."); - PrintHelp(); - return false; - } - - return true; - } - - option = current; - if (index + 1 >= arguments.Length) - { - Console.Error.WriteLine($"Option '{option}' must be followed by a value."); + Console.Error.WriteLine($"Option '{current}' must use the --name=value syntax."); PrintHelp(); return false; } - value = arguments[index + 1]; - index += 2; + option = current[..equalsIndex]; + value = current[(equalsIndex + 1)..]; + index++; return true; } @@ -215,19 +200,19 @@ internal static class Program Console.WriteLine(); Console.WriteLine("Usage:"); Console.WriteLine( - " EvenPerfectBitScanner.ResultsParser [--p-min ] [--p-max ] [--threads ] [--buffer-size ]"); + " EvenPerfectBitScanner.ResultsParser [--p-min=] [--p-max=] [--threads=] [--buffer-size=]"); Console.WriteLine(); Console.WriteLine("The program accepts the following help switches:"); Console.WriteLine(" --?, -?, /?, -help, --help, --h, -h, /h, /help"); Console.WriteLine(); Console.WriteLine("Optional range arguments allow filtering primes by exponent:"); - Console.WriteLine(" --p-min - include entries with p >= value"); - Console.WriteLine(" --p-max - include entries with p <= value"); + Console.WriteLine(" --p-min= - include entries with p >= value"); + Console.WriteLine(" --p-max= - include entries with p <= value"); Console.WriteLine(); Console.WriteLine("Parallel processing options:"); - Console.WriteLine(" --threads - number of worker threads used for parsing and splitting (default: logical cores)"); - Console.WriteLine(" --buffer-size - number of records read into each parsing batch (default: 4096)"); - Console.WriteLine("Values can also be provided using the --option=value syntax."); + Console.WriteLine(" --threads= - number of worker threads used for parsing and splitting (default: logical cores)"); + Console.WriteLine(" --buffer-size= - number of records read into each parsing batch (default: 4096)"); + Console.WriteLine("Values must be provided using the --option=value syntax."); Console.WriteLine(); Console.WriteLine("Outputs prime results into four files placed next to the source file:"); Console.WriteLine(" raw-primes- - prime entries in the original order"); @@ -236,7 +221,7 @@ internal static class Program Console.WriteLine(" sorted-primes-rejected- - sorted prime entries with passedAllTests = false"); Console.WriteLine(); Console.WriteLine("Example:"); - Console.WriteLine(" EvenPerfectBitScanner.ResultsParser results.csv --p-min 89 --p-max 107"); + Console.WriteLine(" EvenPerfectBitScanner.ResultsParser results.csv --p-min=89 --p-max=107"); } private static void ProcessFile(in string inputPath, ulong pMin, ulong pMax, int threadCount, int bufferSize)