@@ -4,18 +4,11 @@ namespace GitVersion
44 using System . Collections . Generic ;
55 using System . Collections . Specialized ;
66 using System . Linq ;
7- using System . Reflection ;
87 using System . Text . RegularExpressions ;
98
109
1110 public class ArgumentParser
1211 {
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-
1912 public static Arguments ParseArguments ( string commandLineArguments )
2013 {
2114 return ParseArguments ( commandLineArguments . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ) ;
@@ -185,9 +178,23 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
185178 throw new WarningException ( "assemblyversionformat switch removed, use AssemblyVersioningScheme configuration value instead" ) ;
186179 }
187180
188- if ( ( IsSwitch ( "v" , name ) ) && VersionParts . Contains ( value . ToLower ( ) ) )
181+ if ( IsSwitch ( "v" , name ) || IsSwitch ( "showvariable" , name ) )
189182 {
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 ;
191198 continue ;
192199 }
193200
@@ -297,7 +304,5 @@ static bool IsHelp(string singleArgument)
297304 IsSwitch ( "help" , singleArgument ) ||
298305 IsSwitch ( "?" , singleArgument ) ;
299306 }
300-
301- static string [ ] VersionParts ;
302307 }
303308}
0 commit comments