Skip to content

Provide a better way to hook custom help #2588

Open

Description

@blowdart

Having to define internal sealed class CustomHelpAction(HelpAction action) : SynchronousCommandLineAction and then loop through Options on the rootCommand looking for is HelpOption is a lot of ceremony.

Could we have something like

var rootCommand = new RootCommand("RootCommand")
{
  myArgument,
  myOption1,
  myOption2,
  HelpAction => () { Console.Writeline("Easy help!") }
};

or

rootCommand.SetHelp((cancellationToken) =>
{
   Console.Writeline("Easy help!")
}

Activity

  1. modified the milestones: Triage, Future on Sep 16, 2025
  2. fourpastmidnight commented on Nov 12, 2025

    @fourpastmidnight

    I would rather have the old HelpBuilder made public once again. I used that feature extensively in one of my projects that I need to update with the new System.CommandLine library that was just released, but now, I cannot customize the help anymore! Lame! All I can do is add text before/after the main help output, but I can't actually change the main help output in any way other than setting a description on options and setting a HelpName property. This is not sufficient for modifying help output. Using the (still existing, albeit now internal) HelpBuilder was easy and painless. This is a reduction in useful functionality.

  3. fourpastmidnight commented on Nov 14, 2025

    @fourpastmidnight

    So, there's not too much entanglement from "internal" or "private" only things in System.CommandLine with respect to help. So, I'm forced to basically copy HelpBuilder and HelpContext and other associated classes, including the localization resources--but after doing all of that, and restoring the OnCustomize property of the HelpBuilder, the old functionality is back and working just like before. The main difference being that all the action is kicked off in a new HelpAction class, that itself is really a SynchronousCommandAction object. So, implementing a new one of those and assigning my own implementation to HelpOption is the biggest change, but that change was trivial.

    I'm not really sure why this was taken "private". The only thing I can think of is there are planned bigger changes around help, and limiting people's dependence on this component could make it easier for these changes to occur without breaking more people? That's the only plausible reason I can see for this bizarre change. I mean, the HelpBuilder is a bit convoluted and not really extensible, so, there's that. And I would applaud a more extensible design of the help system within System.CommandLine. Other than that, I really need this functionality. So I'm glad to have a "workaround", albeit a desperate one.

  4. FrankRay78 commented on Dec 19, 2025

    @FrankRay78

    I've managed to replicate the beautiful rendering Spectre.Console.Cli provides out of the box for help, for System.CommandLine. See below FYI.

    I wonder, given the extent of apparent unhappiness towards the inability to customise help output, if it should be made into a System.CommandLine NuGet extension (for those not wishing to, or are unable to, embrace the Spectre.Console awesomeness)

    Single class implementation: https://github.com/FrankRay78/NetPace/blob/Spectre.Console-Help-Provider-for-System.CommandLine/src/NetPace.Console/CustomHelpProvider.cs (a few hardcoded strings, nothing that couldn't be extracted out quite simply)

    A really nice output:

    Image
  5. jonsequitur commented on Dec 19, 2025

    @jonsequitur
    Contributor

    @fourpastmidnight I'm glad it wasn't too much of a pain to use the old HelpBuilder by copying the code. A number of projects have taken the same approach, and this was intentional.

    I'm not really sure why this was taken "private".

    The implementation was made internal because it had a large surface area to try to maintain, no one loved it, and it fell short of people's needs in many ways. A few years ago we attempted a more flexible approach via a kind of markup language with the experimental System.CommandLine.Rendering. When Spectre.Console took a similar approach with much more polish, we stopped working on System.CommandLine.Rendering.

    The ability to replace HelpAction allows a single extension point where can take over help output entirely. It's more work to customize if you just want to change small details, but it's completely open-ended. And to @FrankRay78's point, it allows people to publish their own packages with more control to create new help experiences.

  6. fourpastmidnight commented on Jul 2, 2026

    @fourpastmidnight

    @jonsequitur Thanks for the additional context on this change, and affirming that using your own HelpAction is the intended way to override help. I agree, this is a LOT more work. It would be nice to provide some targeted seams that would allow people to "tweak" details about "conventional" help output, but, leaving setting your own HelpAction as more of the "sledgehammer" to allow people to completely replace the output, where that's necessary.

    For the most part, other than the "extensibility" being a bit kludgy, the old HelpBuilder, I thought, was a step in the right direction. But to your point, using Spectre.Console.Cli maybe makes this "heavy lifting" to customize output a bit less burdensome.

    Again, thanks for the context.

    Oh, and one last thing: it might be nice to document that setting your own HelpAction is the way to customize help output. That wasn't clear to me, especially coming from the previous version of System.CommandLine.

  7. jonsequitur commented on Jul 2, 2026

    @jonsequitur
    Contributor

    affirming that using your own HelpAction is the intended way to override help. I agree, this is a LOT more work.

    This is the intent. And agreed, it is more work. So I recently created a package to help out with this by providing a source-compatible but public drop-in version of the HelpBuilder API:

    NuGet: https://www.nuget.org/packages/HelpLine.HelpBuilder
    GitHub: https://github.com/jonsequitur/system-commandline-extensions/tree/main/src/HelpLine.HelpBuilder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Helpenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions