Skip to content

Commit 2acce54

Browse files
Made help option lookup symbol, not string based
1 parent 7facb86 commit 2acce54

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/System.CommandLine.Subsystems/HelpSubsystem.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.CommandLine.Subsystems.Annotations;
55
using System.CommandLine.Subsystems;
6+
using static System.Runtime.InteropServices.JavaScript.JSType;
67

78
namespace System.CommandLine;
89

@@ -18,31 +19,30 @@ namespace System.CommandLine;
1819
public class HelpSubsystem(IAnnotationProvider? annotationProvider = null)
1920
: CliSubsystem(HelpAnnotations.Prefix, SubsystemKind.Help, annotationProvider)
2021
{
21-
public void SetDescription(CliSymbol symbol, string description)
22-
=> SetAnnotation(symbol, HelpAnnotations.Description, description);
22+
public CliOption<bool> HelpOption { get; } =new CliOption<bool>("--help", ["-h"])
23+
{
24+
// TODO: Why don't we accept bool like any other bool option?
25+
Arity = ArgumentArity.Zero
26+
};
2327

28+
public void SetDescription(CliSymbol symbol, string description)
29+
=> SetAnnotation(symbol, HelpAnnotations.Description, description);
2430
public string GetDescription(CliSymbol symbol)
2531
=> TryGetAnnotation<string>(symbol, HelpAnnotations.Description, out var value)
2632
? value
2733
: "";
28-
2934
public AnnotationAccessor<string> Description
3035
=> new(this, HelpAnnotations.Description);
3136

3237
protected internal override CliConfiguration Initialize(InitializationContext context)
3338
{
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);
39+
context.Configuration.RootCommand.Add(HelpOption);
4040

4141
return context.Configuration;
4242
}
4343

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

4747
protected internal override CliExit Execute(PipelineContext pipelineContext)
4848
{

0 commit comments

Comments
 (0)