@@ -139,7 +139,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
139139
140140 var expr = invocationExpression . Expression as MemberAccessExpressionSyntax ;
141141 var methodName = expr ? . Name . Identifier . Text ;
142- if ( methodName is "Add" or "UseFilter" or "Run" or "RunAsync" or "ConfigureGlobalOption " )
142+ if ( methodName is "Add" or "UseFilter" or "Run" or "RunAsync" or "ConfigureGlobalOptions " )
143143 {
144144 return true ;
145145 }
@@ -295,7 +295,17 @@ static void EmitConsoleAppBuilder(SourceProductionContext sourceProductionContex
295295 using ( help . BeginBlock ( "internal static partial class ConsoleApp" ) )
296296 using ( help . BeginBlock ( "internal partial class ConsoleAppBuilder" ) )
297297 {
298- // TODO: collectBuilderContext.GlobalOptions
298+ if ( collectBuilderContext . GlobalOptions . Length != 0 )
299+ {
300+ // override commandIds
301+ var globalOptionParameters = collectBuilderContext . GlobalOptions . Select ( x => x . ToDummyCommandParameter ( ) ) ;
302+ commandIds = commandIds . Select ( x =>
303+ {
304+ var newCommand = x . Command with { Parameters = new ( x . Command . Parameters . Concat ( globalOptionParameters ) . ToArray ( ) ) } ;
305+ return x with { Command = newCommand } ;
306+ } )
307+ . ToArray ( ) ;
308+ }
299309
300310 var emitter = new Emitter ( dllReference ) ;
301311 emitter . EmitHelp ( help , commandIds ! ) ;
@@ -482,7 +492,7 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
482492 return commands ;
483493 } ) ;
484494
485- var configureGlobalOptionsGroup = methodGroup [ "ConfigureGlobalOption " ] ;
495+ var configureGlobalOptionsGroup = methodGroup [ "ConfigureGlobalOptions " ] ;
486496 if ( configureGlobalOptionsGroup . Count ( ) >= 2 )
487497 {
488498 // TODO: Diagnostics
@@ -547,29 +557,29 @@ public CollectBuilderContext(ConsoleAppFrameworkGeneratorOptions generatorOption
547557 }
548558
549559 var arguments = node . ArgumentList . Arguments ;
550- if ( arguments . Count >= 2 ) // string name
560+ if ( arguments . Count >= 1 ) // string name
551561 {
552- var constant = model . GetConstantValue ( arguments [ 1 ] . Expression ) ; // TODO: check
562+ var constant = model . GetConstantValue ( arguments [ 0 ] . Expression ) ; // TODO: check
553563 name = constant . Value ! . ToString ( ) ;
554564 }
555565
556566
557567 // TODO: use named argument???
558568
559- if ( arguments . Count >= 3 ) // string description = ""
569+ if ( arguments . Count >= 2 ) // string description = ""
560570 {
561571 // is defaultValue???
562572
563573
564- var constant = model . GetConstantValue ( arguments [ 2 ] . Expression ) ;
574+ var constant = model . GetConstantValue ( arguments [ 1 ] . Expression ) ;
565575 description = constant . Value ! . ToString ( ) ;
566576 }
567577
568578 if ( ! isRequired )
569579 {
570- if ( arguments . Count >= 4 ) // T defaultValue = default(T)
580+ if ( arguments . Count >= 3 ) // T defaultValue = default(T)
571581 {
572- var constant = model . GetConstantValue ( arguments [ 3 ] . Expression ) ;
582+ var constant = model . GetConstantValue ( arguments [ 2 ] . Expression ) ; // ???
573583 defaultValue = constant . Value ! ;
574584 }
575585 else
0 commit comments