11namespace UniqueFileGenerator ;
22
3- public record Arguments ( uint Count , Dictionary < string , string > argDict ) ;
3+ public sealed record ParsedArguments ( uint FileCount , Dictionary < string , string > FlagValueMap ) ;
44
55public static class ArgParser
66{
77 private static readonly IReadOnlyList < string > SupportedFlags =
8- new List < string > ( ) { "-p" , "-e" , "-o" , "-s" , "-d" } ;
8+ new List < string > ( ) {
9+ "-p" , // Prefix
10+ "-e" , // Extension
11+ "-o" , // Output directory
12+ "-s" , // Size
13+ "-d" // Delay
14+ } ;
915
10- public static Arguments ParseArgs ( string [ ] args )
16+ public static ParsedArguments ParseArgs ( string [ ] args )
1117 {
1218 if ( args . Length == 0 )
1319 throw new ArgumentException ( Resources . FileCountMissing , nameof ( args ) ) ;
@@ -17,12 +23,12 @@ public static Arguments ParseArgs(string[] args)
1723 var fileCountText = argQueue . Dequeue ( ) . Replace ( "," , "" ) ;
1824 if ( ! uint . TryParse ( fileCountText , out var fileCount ) )
1925 {
20- // If all characters are digits, then a number that was too high was provided.
26+ // Parsing failed. If all characters are digits,
27+ // then a number that was too large was provided.
2128 if ( fileCountText . All ( char . IsDigit ) )
2229 throw new InvalidOperationException ( Resources . FileCountTooHigh ) ;
2330
24- // Otherwise, some invalid string was provided --
25- // e.g., negative number, letters, symbols, etc.
31+ // Otherwise, some invalid characters were provided.
2632 throw new InvalidOperationException ( Resources . FileCountInvalidRange ) ;
2733 }
2834
@@ -41,7 +47,6 @@ public static Arguments ParseArgs(string[] args)
4147 {
4248 var thisArg = argQueue . Dequeue ( ) ;
4349
44- // If this is a supported flag.
4550 if ( SupportedFlags . Contains ( thisArg ) )
4651 {
4752 // Flags cannot be used twice.
@@ -50,7 +55,7 @@ public static Arguments ParseArgs(string[] args)
5055
5156 currentFlag = thisArg ;
5257 }
53- // Otherwise, consider this a value for the current flag.
58+ // Treat the arg as a value for the current flag.
5459 else
5560 {
5661 if ( string . IsNullOrWhiteSpace ( currentFlag ) )
@@ -67,6 +72,6 @@ public static Arguments ParseArgs(string[] args)
6772 }
6873 }
6974
70- return new Arguments ( fileCount , argDict ) ;
75+ return new ParsedArguments ( fileCount , argDict ) ;
7176 }
7277}
0 commit comments