@@ -73,6 +73,7 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
7373 using ( command . HasFilter ? sb . Nop : sb . BeginBlock ( "try" ) )
7474 {
7575 // prepare commandArgsMemory
76+ var noCommandArgsMemory = false ;
7677 if ( command . HasFilter )
7778 {
7879 sb . AppendLine ( "var commandArgsMemory = context.InternalCommandArgs;" ) ; // already prepared and craeted ConsoleAppContext
@@ -91,11 +92,16 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
9192 }
9293 else
9394 {
94- sb . AppendLine ( "ReadOnlyMemory<string> commandArgsMemory = args;" ) ;
95+ noCommandArgsMemory = true ; // emit help directly
96+ sb . AppendLine ( $ "ReadOnlySpan<string> commandArgs = args;") ;
97+ sb . AppendLine ( $ "if (TryShowHelpOrVersion(commandArgs, { requiredParsableParameterCount } , { commandWithId . Id } )) return;") ;
9598 }
9699 }
97100
98- sb . AppendLine ( $ "if (TryShowHelpOrVersion(commandArgsMemory.Span, { requiredParsableParameterCount } , { commandWithId . Id } )) return;") ;
101+ if ( ! noCommandArgsMemory )
102+ {
103+ sb . AppendLine ( $ "if (TryShowHelpOrVersion(commandArgsMemory.Span, { requiredParsableParameterCount } , { commandWithId . Id } )) return;") ;
104+ }
99105 sb . AppendLine ( ) ;
100106
101107 // setup-timer
@@ -198,7 +204,10 @@ public void EmitRun(SourceBuilder sb, CommandWithId commandWithId, bool isRunAsy
198204 sb . AppendLine ( "var argumentPosition = 0;" ) ;
199205 }
200206
201- sb . AppendLine ( "var commandArgs = commandArgsMemory.Span;" ) ;
207+ if ( ! noCommandArgsMemory )
208+ {
209+ sb . AppendLine ( "var commandArgs = commandArgsMemory.Span;" ) ;
210+ }
202211 using ( sb . BeginBlock ( "for (int i = 0; i < commandArgs.Length; i++)" ) )
203212 {
204213 sb . AppendLine ( "var name = commandArgs[i];" ) ;
0 commit comments