Skip to content

Commit 50566f7

Browse files
Merge pull request #2408 from KathleenDollard/help-use-symbol
Help uses symbol to lookup if help is selected
2 parents 5306e87 + 45383ce commit 50566f7

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/System.CommandLine.Subsystems/HelpSubsystem.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,35 @@ namespace System.CommandLine;
1515
// var command = new CliCommand("greet")
1616
// .With(help.Description, "Greet the user");
1717
//
18-
public class HelpSubsystem(IAnnotationProvider? annotationProvider = null)
18+
public class HelpSubsystem(IAnnotationProvider? annotationProvider = null)
1919
: CliSubsystem(HelpAnnotations.Prefix, SubsystemKind.Help, annotationProvider)
2020
{
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)
2228
=> SetAnnotation(symbol, HelpAnnotations.Description, description);
2329

24-
public string GetDescription(CliSymbol symbol)
30+
public string GetDescription(CliSymbol symbol)
2531
=> TryGetAnnotation<string>(symbol, HelpAnnotations.Description, out var value)
2632
? value
2733
: "";
2834

29-
public AnnotationAccessor<string> Description
35+
public AnnotationAccessor<string> Description
3036
=> new(this, HelpAnnotations.Description);
3137

3238
protected internal override CliConfiguration Initialize(InitializationContext context)
3339
{
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);
4041

4142
return context.Configuration;
4243
}
4344

4445
protected internal override bool GetIsActivated(ParseResult? parseResult)
45-
=> parseResult is not null && parseResult.GetValue<bool>("--help");
46+
=> parseResult is not null && parseResult.GetValue(HelpOption);
4647

4748
protected internal override CliExit Execute(PipelineContext pipelineContext)
4849
{

0 commit comments

Comments
 (0)