@@ -4,18 +4,11 @@ namespace GitVersion
4
4
using System . Collections . Generic ;
5
5
using System . Collections . Specialized ;
6
6
using System . Linq ;
7
- using System . Reflection ;
8
7
using System . Text . RegularExpressions ;
9
8
10
9
11
10
public class ArgumentParser
12
11
{
13
- static ArgumentParser ( )
14
- {
15
- var fields = typeof ( VariableProvider ) . GetFields ( BindingFlags . Public | BindingFlags . Static ) ;
16
- VersionParts = fields . Select ( x => x . Name . ToLower ( ) ) . ToArray ( ) ;
17
- }
18
-
19
12
public static Arguments ParseArguments ( string commandLineArguments )
20
13
{
21
14
return ParseArguments ( commandLineArguments . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ) ;
@@ -185,9 +178,23 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
185
178
throw new WarningException ( "assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead" ) ;
186
179
}
187
180
188
- if ( ( IsSwitch ( "v" , name ) ) && VersionParts . Contains ( value . ToLower ( ) ) )
181
+ if ( IsSwitch ( "v" , name ) || IsSwitch ( "showvariable" , name ) )
189
182
{
190
- arguments . ShowVariable = value . ToLower ( ) ;
183
+ string versionVariable = null ;
184
+
185
+ if ( ! string . IsNullOrWhiteSpace ( value ) )
186
+ {
187
+ versionVariable = VersionVariables . AvailableVariables . SingleOrDefault ( av => av . Equals ( value . Replace ( "'" , "" ) , StringComparison . CurrentCultureIgnoreCase ) ) ;
188
+ }
189
+
190
+ if ( versionVariable == null )
191
+ {
192
+ var messageFormat = "{0} requires a valid version variable. Available variables are:\n {1}" ;
193
+ var message = string . Format ( messageFormat , name , String . Join ( ", " , VersionVariables . AvailableVariables . Select ( x=> string . Concat ( "'" , x , "'" ) ) ) ) ;
194
+ throw new WarningException ( message ) ;
195
+ }
196
+
197
+ arguments . ShowVariable = versionVariable ;
191
198
continue ;
192
199
}
193
200
@@ -297,7 +304,5 @@ static bool IsHelp(string singleArgument)
297
304
IsSwitch ( "help" , singleArgument ) ||
298
305
IsSwitch ( "?" , singleArgument ) ;
299
306
}
300
-
301
- static string [ ] VersionParts ;
302
307
}
303
308
}
0 commit comments