@@ -90,161 +90,8 @@ public Arguments ParseArguments(string[] commandLineArguments)
9090 }
9191 catch ( Exception )
9292 {
93- // If parsing fails, try to handle legacy forward slash syntax
94- return HandleLegacySyntax ( commandLineArguments ) ;
95- }
96-
97- return CreateDefaultArguments ( ) ;
98- }
99-
100- private Arguments HandleLegacySyntax ( string [ ] commandLineArguments )
101- {
102- // Convert legacy forward slash syntax to hyphen syntax for Spectre.Console.Cli
103- var convertedArgs = new List < string > ( ) ;
104-
105- for ( int i = 0 ; i < commandLineArguments . Length ; i ++ )
106- {
107- var arg = commandLineArguments [ i ] ;
108-
109- // Handle legacy forward slash options
110- if ( arg . StartsWith ( '/' ) )
111- {
112- var option = arg . Substring ( 1 ) . ToLowerInvariant ( ) ;
113- switch ( option )
114- {
115- case "output" :
116- convertedArgs . Add ( "--output" ) ;
117- break ;
118- case "outputfile" :
119- convertedArgs . Add ( "--output-file" ) ;
120- break ;
121- case "showvariable" :
122- convertedArgs . Add ( "--show-variable" ) ;
123- break ;
124- case "format" :
125- convertedArgs . Add ( "--format" ) ;
126- break ;
127- case "l" :
128- convertedArgs . Add ( "--log-file" ) ;
129- break ;
130- case "config" :
131- convertedArgs . Add ( "--config" ) ;
132- break ;
133- case "showconfig" :
134- convertedArgs . Add ( "--show-config" ) ;
135- break ;
136- case "overrideconfig" :
137- convertedArgs . Add ( "--override-config" ) ;
138- // Handle the key=value format for override config
139- if ( i + 1 < commandLineArguments . Length )
140- {
141- var nextArg = commandLineArguments [ i + 1 ] ;
142- if ( nextArg . Contains ( '=' ) && ! nextArg . StartsWith ( '/' ) && ! nextArg . StartsWith ( '-' ) )
143- {
144- // This is the key=value pair for override config
145- convertedArgs . Add ( nextArg ) ;
146- i ++ ; // Skip the next argument since we consumed it
147- }
148- }
149- break ;
150- case "nocache" :
151- convertedArgs . Add ( "--no-cache" ) ;
152- break ;
153- case "nonormalize" :
154- convertedArgs . Add ( "--no-normalize" ) ;
155- break ;
156- case "allowshallow" :
157- convertedArgs . Add ( "--allow-shallow" ) ;
158- break ;
159- case "verbosity" :
160- convertedArgs . Add ( "--verbosity" ) ;
161- break ;
162- case "updateassemblyinfo" :
163- convertedArgs . Add ( "--update-assembly-info" ) ;
164- break ;
165- case "updateprojectfiles" :
166- convertedArgs . Add ( "--update-project-files" ) ;
167- break ;
168- case "ensureassemblyinfo" :
169- convertedArgs . Add ( "--ensure-assembly-info" ) ;
170- break ;
171- case "updatewixversionfile" :
172- convertedArgs . Add ( "--update-wix-version-file" ) ;
173- break ;
174- case "url" :
175- convertedArgs . Add ( "--url" ) ;
176- break ;
177- case "b" :
178- convertedArgs . Add ( "--branch" ) ;
179- break ;
180- case "u" :
181- convertedArgs . Add ( "--username" ) ;
182- break ;
183- case "p" :
184- convertedArgs . Add ( "--password" ) ;
185- break ;
186- case "c" :
187- convertedArgs . Add ( "--commit" ) ;
188- break ;
189- case "dynamicrepolocation" :
190- convertedArgs . Add ( "--dynamic-repo-location" ) ;
191- break ;
192- case "nofetch" :
193- convertedArgs . Add ( "--no-fetch" ) ;
194- break ;
195- case "targetpath" :
196- convertedArgs . Add ( "--target-path" ) ;
197- break ;
198- case "diag" :
199- convertedArgs . Add ( "--diag" ) ;
200- break ;
201- default :
202- // Unknown option, keep as is
203- convertedArgs . Add ( arg ) ;
204- break ;
205- }
206- }
207- else if ( ! arg . StartsWith ( '-' ) && i == 0 )
208- {
209- // First non-option argument is likely the target path
210- convertedArgs . Add ( arg ) ;
211- }
212- else
213- {
214- // Regular argument or already in correct format
215- convertedArgs . Add ( arg ) ;
216- }
217- }
218-
219- // Try parsing again with converted arguments
220- try
221- {
222- var app = new CommandApp < GitVersionCommand > ( ) ;
223- app . Configure ( config =>
224- {
225- config . SetApplicationName ( "gitversion" ) ;
226- config . PropagateExceptions ( ) ;
227- } ) ;
228-
229- var resultStorage = new ParseResultStorage ( ) ;
230- var interceptor = new ArgumentInterceptor ( resultStorage , this . environment , this . fileSystem , this . buildAgent , this . console , this . globbingResolver ) ;
231- app . Configure ( config => config . Settings . Interceptor = interceptor ) ;
232-
233- var parseResult = app . Run ( convertedArgs . ToArray ( ) ) ;
234-
235- var result = resultStorage . GetResult ( ) ;
236- if ( result != null )
237- {
238- return result ;
239- }
240- }
241- catch ( Exception )
242- {
243- // Final fallback - if it's a single argument and not an option, treat as target path
244- if ( commandLineArguments . Length == 1 && ! commandLineArguments [ 0 ] . StartsWith ( '-' ) && ! commandLineArguments [ 0 ] . StartsWith ( '/' ) )
245- {
246- return CreateArgumentsWithTargetPath ( commandLineArguments [ 0 ] ) ;
247- }
93+ // If parsing fails, return default arguments
94+ return CreateDefaultArguments ( ) ;
24895 }
24996
25097 return CreateDefaultArguments ( ) ;
@@ -262,18 +109,6 @@ private Arguments CreateDefaultArguments()
262109 return args ;
263110 }
264111
265- private Arguments CreateArgumentsWithTargetPath ( string targetPath )
266- {
267- var args = new Arguments
268- {
269- TargetPath = targetPath . TrimEnd ( '/' , '\\ ' )
270- } ;
271- args . Output . Add ( OutputType . Json ) ;
272- AddAuthentication ( args ) ;
273- args . NoFetch = this . buildAgent . PreventFetch ( ) ;
274- return args ;
275- }
276-
277112 private void AddAuthentication ( Arguments arguments )
278113 {
279114 var username = this . environment . GetEnvironmentVariable ( "GITVERSION_REMOTE_USERNAME" ) ;
@@ -437,12 +272,24 @@ private static Arguments ConvertToArguments(GitVersionSettings settings)
437272 // Handle override configuration
438273 if ( settings . OverrideConfiguration != null && settings . OverrideConfiguration . Any ( ) )
439274 {
440- var overrideConfig = new Dictionary < object , object ? > ( ) ;
275+ var parser = new OverrideConfigurationOptionParser ( ) ;
276+
441277 foreach ( var kvp in settings . OverrideConfiguration )
442278 {
443- overrideConfig [ kvp . Key ] = kvp . Value ;
279+ // Validate the key format - Spectre.Console.Cli should have already parsed key=value correctly
280+ // but we still need to validate against supported properties
281+ var keyValueOption = $ "{ kvp . Key } ={ kvp . Value } ";
282+
283+ var optionKey = kvp . Key . ToLowerInvariant ( ) ;
284+ if ( ! OverrideConfigurationOptionParser . SupportedProperties . Contains ( optionKey ) )
285+ {
286+ throw new WarningException ( $ "Could not parse --override-config option: { keyValueOption } . Unsupported 'key'.") ;
287+ }
288+
289+ parser . SetValue ( optionKey , kvp . Value ) ;
444290 }
445- arguments . OverrideConfiguration = overrideConfig ;
291+
292+ arguments . OverrideConfiguration = parser . GetOverrideConfiguration ( ) ;
446293 }
447294 else
448295 {
0 commit comments