dotnet / dotnet/command-line-api

Improve Help customization

Open
#2,234 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

Current version: 2.0.0-beta4.23307.1 of S.CL

# Description

I wanted to customize my help

* I wanted options/aliases sorted by length, so it always shows `-s, --sl, --something-long`
* I want my options to be sorted (I can do this with `CustomizeSymbol`
* Add additional help text based on validators (I haven't found a good solution for this).
* I have validators that check for mutually exclusive options and wanted to call out the options in the help
* I have options that can mutate their required state, e.g., if you have option A and B, then C becomes required.

For sorting the options, all I really needed was a way to change the `OptionSeciton` https://github.com/dotnet/command-line-api/blob/f6ff2f1a94a58617e744f8fe0d469a2a420a6259/src/System.CommandLine/Help/HelpBuilder.Default.cs#L240

to

```csharp
ctx.HelpBuilder.WriteColumns(optionRows.OrderBy(o=>o.FirstColumnText).ToList(), ctx);
```

To do this I had to
* copy the `OptionSection` code,
* Workaround the accessibility of `ParentNode` (it's internal) and I'm not sure how safe my workaround is.
```csharp
CliCommand parentCommand = null;
var parent = current.Parents.FirstOrDefault();
```
* Implement my own version of `WriteHeading` (it's marked as private)

Are there any plans on improving S.CL help customization or expose more extension points?

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.