@@ -94,7 +94,7 @@ public void Option_can_customize_first_column_text_based_on_parse_result()
94
94
: optionBFirstColumnText ) ;
95
95
command . Options . Add ( new HelpOption ( )
96
96
{
97
- Action = new HelpAction ( )
97
+ Action = new CustomHelpAction ( )
98
98
{
99
99
Builder = helpBuilder
100
100
}
@@ -140,7 +140,7 @@ public void Option_can_customize_second_column_text_based_on_parse_result()
140
140
: optionBDescription ) ;
141
141
command . Options . Add ( new HelpOption
142
142
{
143
- Action = new HelpAction
143
+ Action = new CustomHelpAction
144
144
{
145
145
Builder = helpBuilder
146
146
}
@@ -269,7 +269,7 @@ public void Option_can_fallback_to_default_when_customizing(bool conditionA, boo
269
269
270
270
command . Options . Add ( new HelpOption
271
271
{
272
- Action = new HelpAction
272
+ Action = new CustomHelpAction
273
273
{
274
274
Builder = helpBuilder
275
275
}
@@ -317,7 +317,7 @@ public void Argument_can_fallback_to_default_when_customizing(
317
317
318
318
command . Options . Add ( new HelpOption
319
319
{
320
- Action = new HelpAction
320
+ Action = new CustomHelpAction
321
321
{
322
322
Builder = helpBuilder
323
323
}
@@ -336,11 +336,20 @@ public void Individual_symbols_can_be_customized()
336
336
var option = new Option < int > ( "-x" ) { Description = "The default option description" } ;
337
337
var argument = new Argument < int > ( "int-value" ) { Description = "The default argument description" } ;
338
338
339
- var rootCommand = new RootCommand
339
+ CustomHelpAction helpAction = new ( ) ;
340
+ helpAction . Builder . CustomizeSymbol ( subcommand , secondColumnText : "The custom command description" ) ;
341
+ helpAction . Builder . CustomizeSymbol ( option , secondColumnText : "The custom option description" ) ;
342
+ helpAction . Builder . CustomizeSymbol ( argument , secondColumnText : "The custom argument description" ) ;
343
+
344
+ var rootCommand = new Command ( "name" )
340
345
{
341
346
subcommand ,
342
347
option ,
343
348
argument ,
349
+ new HelpOption ( )
350
+ {
351
+ Action = helpAction
352
+ }
344
353
} ;
345
354
346
355
CommandLineConfiguration config = new ( rootCommand )
@@ -350,13 +359,6 @@ public void Individual_symbols_can_be_customized()
350
359
351
360
ParseResult parseResult = rootCommand . Parse ( "-h" , config ) ;
352
361
353
- if ( parseResult . Action is HelpAction helpAction )
354
- {
355
- helpAction . Builder . CustomizeSymbol ( subcommand , secondColumnText : "The custom command description" ) ;
356
- helpAction . Builder . CustomizeSymbol ( option , secondColumnText : "The custom option description" ) ;
357
- helpAction . Builder . CustomizeSymbol ( argument , secondColumnText : "The custom argument description" ) ;
358
- }
359
-
360
362
parseResult . Invoke ( ) ;
361
363
362
364
config . Output
@@ -370,18 +372,16 @@ public void Individual_symbols_can_be_customized()
370
372
[ Fact ]
371
373
public void Help_sections_can_be_replaced ( )
372
374
{
373
- CommandLineConfiguration config = new ( new RootCommand ( ) )
375
+ CustomHelpAction helpAction = new ( ) ;
376
+ helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
377
+
378
+ CommandLineConfiguration config = new ( new Command ( "name" ) { new HelpOption ( ) { Action = helpAction } } )
374
379
{
375
380
Output = new StringWriter ( )
376
381
} ;
377
382
378
383
ParseResult parseResult = config . Parse ( "-h" ) ;
379
384
380
- if ( parseResult . Action is HelpAction helpAction )
381
- {
382
- helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
383
- }
384
-
385
385
parseResult . Invoke ( ) ;
386
386
387
387
config . Output . ToString ( ) . Should ( ) . Be ( $ "one{ NewLine } { NewLine } two{ NewLine } { NewLine } three{ NewLine } { NewLine } ") ;
@@ -397,20 +397,18 @@ IEnumerable<Func<HelpContext, bool>> CustomLayout(HelpContext _)
397
397
[ Fact ]
398
398
public void Help_sections_can_be_supplemented ( )
399
399
{
400
- CommandLineConfiguration config = new ( new RootCommand ( "hello" ) )
400
+ CustomHelpAction helpAction = new ( ) ;
401
+ helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
402
+
403
+ CommandLineConfiguration config = new ( new Command ( "hello" ) { new HelpOption ( ) { Action = helpAction } } )
401
404
{
402
405
Output = new StringWriter ( ) ,
403
406
} ;
404
407
405
- var defaultHelp = GetDefaultHelp ( config . RootCommand ) ;
408
+ var defaultHelp = GetDefaultHelp ( new Command ( "hello" ) ) ;
406
409
407
410
ParseResult parseResult = config . Parse ( "-h" ) ;
408
411
409
- if ( parseResult . Action is HelpAction helpAction )
410
- {
411
- helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
412
- }
413
-
414
412
parseResult . Invoke ( ) ;
415
413
416
414
var output = config . Output . ToString ( ) ;
@@ -444,7 +442,7 @@ public void Layout_can_be_composed_dynamically_based_on_context()
444
442
commandWithCustomHelp
445
443
} ;
446
444
447
- command . Options . OfType < HelpOption > ( ) . Single ( ) . Action = new HelpAction
445
+ command . Options . OfType < HelpOption > ( ) . Single ( ) . Action = new CustomHelpAction
448
446
{
449
447
Builder = helpBuilder
450
448
} ;
@@ -480,7 +478,7 @@ public void Help_default_sections_can_be_wrapped()
480
478
} ,
481
479
new HelpOption
482
480
{
483
- Action = new HelpAction
481
+ Action = new CustomHelpAction
484
482
{
485
483
Builder = new HelpBuilder ( 30 )
486
484
}
@@ -509,19 +507,17 @@ public void Help_default_sections_can_be_wrapped()
509
507
[ Fact ]
510
508
public void Help_customized_sections_can_be_wrapped ( )
511
509
{
512
- CommandLineConfiguration config = new ( new RootCommand ( ) )
510
+ CustomHelpAction helpAction = new ( ) ;
511
+ helpAction . Builder = new HelpBuilder ( 10 ) ;
512
+ helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
513
+
514
+ CommandLineConfiguration config = new ( new Command ( "name" ) { new HelpOption ( ) { Action = helpAction } } )
513
515
{
514
516
Output = new StringWriter ( )
515
517
} ;
516
518
517
519
ParseResult parseResult = config . Parse ( "-h" ) ;
518
520
519
- if ( parseResult . Action is HelpAction helpAction )
520
- {
521
- helpAction . Builder = new HelpBuilder ( 10 ) ;
522
- helpAction . Builder . CustomizeLayout ( CustomLayout ) ;
523
- }
524
-
525
521
parseResult . Invoke ( ) ;
526
522
527
523
string result = config . Output . ToString ( ) ;
0 commit comments