Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating HelpBuilder.WriteColumns to be easier to extend #1722

Closed
wants to merge 1 commit into from

Conversation

Keboo
Copy link
Member

@Keboo Keboo commented Apr 29, 2022

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: dotnet/ClangSharp#343

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.
@jonsequitur
Copy link
Contributor

I wonder if another helper method like this work:

/// <summary>
/// Writes help output for the specified command.
/// </summary>
public static void Write(
this HelpBuilder helpBuilder,
Command command,
TextWriter writer)
{
helpBuilder.Write(new HelpContext(helpBuilder, command, writer));
}

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

@Keboo
Copy link
Member Author

Keboo commented May 9, 2022

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".

@jonsequitur
Copy link
Contributor

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

@Keboo
Copy link
Member Author

Keboo commented May 11, 2022

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?

@jonsequitur
Copy link
Contributor

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.

@Keboo Keboo closed this Jan 31, 2024
@Keboo Keboo deleted the updateWriteColumsn branch January 31, 2024 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants