dotnet / dotnet/command-line-api

Make the help customiztaion "easier"

Open
#2,669 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

The documentation (https://learn.microsoft.com/en-us/dotnet/standard/commandline/how-to-customize-help) shows that when the user wants to customize the help he needs to write a lot of unnecessary code. Create a class which in inherited from `SynchronousCommandLineAction `/ `AsynchronousCommandLineAction`, find the `HelpOption`, etc...

I'd suggest you to simplify this.

For example:
- the `AnonymousSynchronousCommandLineAction` / `AnonymousAsynchronousCommandLineAction` classes (which are used in the `SetAction` methods) could be **public**. So the user can write this:

```
defaultHelpOption.Action = new AnonymousSynchronousCommandLineAction(parseResult =>
{
Console.WriteLine("HEADER");
return oldAction.Invoke(parseResult);
});

```
-
- or replace the XXCommandLineAction classes with just simple delegates:
```
public delegate int SynchronousCommandLineAction(ParseResult parseResult);
public delegate Task AsynchronousCommandLineAction(ParseResult parseResult, CancellationToken cancellationToken);

```

- add helper methods to the root command which returns the Help and `VersionOption`s

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.