command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

Updating HelpBuilder.WriteColumns to be easier to extend

Open Keboo opened this issue 3 years ago • 5 comments

While updating ClangSharp to the latest System.CommandLine I ran into the issue of a custom HelpBuilder wanting to leverage the two column layout for some arbitrary items. This required building a HelpContext despite the method only needing a TextWriter to output to.

See: https://github.com/dotnet/ClangSharp/pull/343

Keboo avatar Apr 29 '22 07:04 Keboo

I wonder if another helper method like this work:

https://github.com/dotnet/command-line-api/blob/74ae46ea8571269a66945049ce9f134a91d67d1e/src/System.CommandLine/Help/HelpBuilderExtensions.cs#L31-L40

HelpBuilder.Write also takes a HelpContext and keeping things consistent on this type leaves an opening to add things to the HelpContext later.

jonsequitur avatar May 07 '22 17:05 jonsequitur

The only issue with that type of extension is it makes is very difficult for anyone to use the built-in two column layout with arbitrary content. For the PR linked above, there is a large bit of content simply wants to be written out using the two-column layout. To work around the API I did something similar, the suggested extension method still assumes that the input to the function will come from a command. Where in this case what is desired is a way for an option to give "help-like" behavior with a lot of additional details. Really that code path doesn't really need to even go through a help builder, it is only using it to get some of the formatting niceness, but the input is "custom".

Keboo avatar May 09 '22 04:05 Keboo

I wonder if that suggests that the problem isn't so much the HelpContext as the fact that it's so Command-centric.

jonsequitur avatar May 10 '22 22:05 jonsequitur

I think that is a good summary. Which brings up two questions. 1. Should it be less command centric? 2. Any thoughts on what that should like?

Keboo avatar May 11 '22 00:05 Keboo

One approach off the top of my head could be to change HelpBuilder.Write to accept Symbol and change HelpContext.Command to HelpContext.Symbol. That might have a bit of a ripple effect, though.

jonsequitur avatar May 11 '22 05:05 jonsequitur