11using System ;
2- using System . Collections . Generic ;
32using System . Linq ;
3+ using System . Collections . Generic ;
44using System . Runtime . CompilerServices ;
55
66namespace PayrollEngine . Client . Command ;
77
88/// <summary>Represents the environment command line arguments</summary>
9- public class CommandLineParser ( string [ ] commandLineArgs )
9+ public class CommandLineParser ( string [ ] arguments )
1010{
11- private string [ ] CommandLineArgs { get ; } = commandLineArgs ?? throw new ArgumentNullException ( nameof ( commandLineArgs ) ) ;
11+ /// <summary>Command line arguments</summary>
12+ public string [ ] Arguments { get ; } = arguments ?? throw new ArgumentNullException ( nameof ( arguments ) ) ;
1213
1314 /// <summary>Get the command line arguments count, excluding the implicit parameter at index 0</summary>
1415 public int ParameterCount =>
1516 Count - 1 ;
1617
1718 /// <summary>Get the command line arguments count</summary>
1819 public int Count =>
19- CommandLineArgs . Length ;
20+ Arguments . Length ;
2021
2122 /// <summary>Determines whether the specified argument exists</summary>
2223 /// <param name="name">The argument</param>
2324 /// <returns>True if the specified argument exists</returns>
2425 private bool Contains ( string name ) =>
25- CommandLineArgs . FirstOrDefault ( x => string . Equals ( name , x , StringComparison . InvariantCultureIgnoreCase ) ) != null ;
26+ Arguments . FirstOrDefault ( x => string . Equals ( name , x , StringComparison . InvariantCultureIgnoreCase ) ) != null ;
2627
2728 /// <summary>Determines whether the specified argument exists</summary>
2829 /// <returns>True if the specified toggle exists</returns>
2930 public bool IsValidOrder ( )
3031 {
31- var arguments = CommandLineArgs ;
3232 int ? firstToggleIndex = null ;
33- for ( var i = 0 ; i < arguments . Length ; i ++ )
33+ for ( var i = 0 ; i < Arguments . Length ; i ++ )
3434 {
35- var argument = arguments [ i ] ;
35+ var argument = Arguments [ i ] ;
3636 if ( IsToggleArgument ( argument ) )
3737 {
3838 firstToggleIndex ??= i ;
@@ -79,8 +79,8 @@ public string GetMember(int index, [CallerMemberName] string memberName = "", bo
7979
8080 /// <summary>Gets the specified index, starting at 1</summary>
8181 /// <param name="index">The argument index</param>
82- /// <param name="name">The argument name (optional )</param>
83- /// <param name="allowToggle">Argument can be a toggle (optional )</param>
82+ /// <param name="name">The argument name (default=null )</param>
83+ /// <param name="allowToggle">Argument can be a toggle (default: false )</param>
8484 /// <returns>The argument value</returns>
8585 public string Get ( int index , string name = null , bool allowToggle = false )
8686 {
@@ -89,7 +89,7 @@ public string Get(int index, string name = null, bool allowToggle = false)
8989 throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
9090 }
9191
92- if ( CommandLineArgs . Length <= index || index >= CommandLineArgs . Length )
92+ if ( Arguments . Length <= index || index >= Arguments . Length )
9393 {
9494 return null ;
9595 }
@@ -104,7 +104,7 @@ public string Get(int index, string name = null, bool allowToggle = false)
104104 }
105105 }
106106
107- var arg = CommandLineArgs [ index ] ;
107+ var arg = Arguments [ index ] ;
108108
109109 // name
110110 if ( name != null )
@@ -130,7 +130,7 @@ public string GetByName(string name)
130130 throw new ArgumentException ( nameof ( name ) ) ;
131131 }
132132 var marker = $ "{ name } :";
133- foreach ( var cmdLineArg in CommandLineArgs )
133+ foreach ( var cmdLineArg in Arguments )
134134 {
135135 if ( cmdLineArg . StartsWith ( marker , StringComparison . InvariantCultureIgnoreCase ) )
136136 {
@@ -249,7 +249,7 @@ public T GetEnum<T>(int index, T defaultValue, string name = null)
249249 /// <summary>Gets all toggle with fallback value</summary>
250250 /// <returns>The argument value</returns>
251251 public IEnumerable < string > GetToggles ( ) =>
252- CommandLineArgs . Where ( IsToggleArgument ) ;
252+ Arguments . Where ( IsToggleArgument ) ;
253253
254254 /// <summary>Gets a toggle with fallback value</summary>
255255 /// <typeparam name="T">The enum type</typeparam>
@@ -265,10 +265,10 @@ public string TestUnknownToggles(IEnumerable<Type> enumTypes)
265265 {
266266 var enumTypesArray = enumTypes . ToArray ( ) ;
267267 // test for unknown toggles
268- for ( var i = 1 ; i < CommandLineArgs . Length ; i ++ )
268+ for ( var i = 1 ; i < Arguments . Length ; i ++ )
269269 {
270270 // command line argument
271- var arg = CommandLineArgs [ i ] ;
271+ var arg = Arguments [ i ] ;
272272 if ( ! IsToggleArgument ( arg ) )
273273 {
274274 continue ;
@@ -315,11 +315,11 @@ public Type TestMultipleToggles(IEnumerable<Type> enumTypes)
315315 /// </summary>
316316 public string [ ] GetArguments ( )
317317 {
318- if ( commandLineArgs . Length <= 2 )
318+ if ( arguments . Length <= 2 )
319319 {
320320 return null ;
321321 }
322- return CommandLineArgs . Skip ( 2 ) . ToArray ( ) ;
322+ return Arguments . Skip ( 2 ) . ToArray ( ) ;
323323 }
324324
325325 #region Static
@@ -328,6 +328,7 @@ public string[] GetArguments()
328328 public static CommandLineParser NewFromEnvironment ( ) =>
329329 new ( Environment . GetCommandLineArgs ( ) ) ;
330330
331+
331332 /// <summary>New command line parser from command string</summary>
332333 public static CommandLineParser NewFromCommand ( string command ) =>
333334 new ( SplitCommandArguments ( command ) ) ;
0 commit comments