@@ -101,13 +101,32 @@ public static IEnumerable<string> ParseLine(string line, LineParseOptions? optio
101
101
return GetValueInternal ( args ?? Environment . GetCommandLineArgs ( ) , optionName ) ?? defaultValue ;
102
102
}
103
103
104
+ /// <summary>
105
+ /// Get argument value from arguments
106
+ /// </summary>
107
+ /// <param name="args">arguments</param>
108
+ /// <param name="defaultValue">default argument value when not found</param>
109
+ /// <param name="optionName">argument name to get value</param>
110
+ /// <returns>argument value</returns>
111
+ [ return : NotNullIfNotNull ( nameof ( defaultValue ) ) ]
112
+ public static string ? Val ( string [ ] args , string optionName , string ? defaultValue = null )
113
+ {
114
+ return GetValueInternal ( args , optionName ) ?? defaultValue ;
115
+ }
104
116
public static bool BooleanVal ( string optionName , string [ ] ? args = null , bool defaultValue = default )
105
117
{
106
118
return GetValueInternal ( args ?? Environment . GetCommandLineArgs ( ) , optionName ) . ToBoolean ( defaultValue ) ;
107
119
}
120
+
121
+ public static bool BooleanVal ( string [ ] args , string optionName , bool defaultValue = default )
122
+ {
123
+ return GetValueInternal ( args , optionName ) . ToBoolean ( defaultValue ) ;
124
+ }
108
125
109
126
private static string ? GetValueInternal ( string [ ] args , string argumentName )
110
127
{
128
+ Guard . NotNull ( args ) ;
129
+ Guard . NotNullOrEmpty ( argumentName ) ;
111
130
for ( var i = 0 ; i < args . Length ; i ++ )
112
131
{
113
132
if ( args [ i ] == $ "--{ argumentName } " || args [ i ] == $ "-{ argumentName } ")
0 commit comments