@@ -15,34 +15,35 @@ namespace System.CommandLine;
15
15
// var command = new CliCommand("greet")
16
16
// .With(help.Description, "Greet the user");
17
17
//
18
- public class HelpSubsystem ( IAnnotationProvider ? annotationProvider = null )
18
+ public class HelpSubsystem ( IAnnotationProvider ? annotationProvider = null )
19
19
: CliSubsystem ( HelpAnnotations . Prefix , SubsystemKind . Help , annotationProvider )
20
20
{
21
- public void SetDescription ( CliSymbol symbol , string description )
21
+ public CliOption < bool > HelpOption { get ; } = new CliOption < bool > ( "--help" , [ "-h" ] )
22
+ {
23
+ // TODO: Why don't we accept bool like any other bool option?
24
+ Arity = ArgumentArity . Zero
25
+ } ;
26
+
27
+ public void SetDescription ( CliSymbol symbol , string description )
22
28
=> SetAnnotation ( symbol , HelpAnnotations . Description , description ) ;
23
29
24
- public string GetDescription ( CliSymbol symbol )
30
+ public string GetDescription ( CliSymbol symbol )
25
31
=> TryGetAnnotation < string > ( symbol , HelpAnnotations . Description , out var value )
26
32
? value
27
33
: "" ;
28
34
29
- public AnnotationAccessor < string > Description
35
+ public AnnotationAccessor < string > Description
30
36
=> new ( this , HelpAnnotations . Description ) ;
31
37
32
38
protected internal override CliConfiguration Initialize ( InitializationContext context )
33
39
{
34
- var option = new CliOption < bool > ( "--help" , [ "-h" ] )
35
- {
36
- // TODO: Why don't we accept bool like any other bool option?
37
- Arity = ArgumentArity . Zero
38
- } ;
39
- context . Configuration . RootCommand . Add ( option ) ;
40
+ context . Configuration . RootCommand . Add ( HelpOption ) ;
40
41
41
42
return context . Configuration ;
42
43
}
43
44
44
45
protected internal override bool GetIsActivated ( ParseResult ? parseResult )
45
- => parseResult is not null && parseResult . GetValue < bool > ( "--help" ) ;
46
+ => parseResult is not null && parseResult . GetValue ( HelpOption ) ;
46
47
47
48
protected internal override CliExit Execute ( PipelineContext pipelineContext )
48
49
{
0 commit comments