Skip to content

expose HelpOption and HelpAction, move help configuration to the action #2102

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

Merged
merged 5 commits into from
Mar 21, 2023

Conversation

adamsitnik
Copy link
Member

We now have two ways of configuring help:

Before parsing:

command.Options.Add(new HelpOption()
{
    Action = new HelpAction()
    {
        Builder = helpBuilder
    }
});

Or after:

ParseResult parseResult = rootCommand.Parse("-h");

if (parseResult.Action is HelpAction helpAction)
{ 
    helpAction.Builder.CustomizeSymbol(subcommand, secondColumnText: "The custom command description");
    helpAction.Builder.CustomizeSymbol(option, secondColumnText: "The custom option description");
    helpAction.Builder.CustomizeSymbol(argument, secondColumnText: "The custom argument description");
}

parseResult.Invoke(console);

}

internal HelpOption() : this("--help", new[] { "-h", "/h", "-?", "/?" })
public HelpOption() : this("--help", new[] { "-h", "/h", "-?", "/?" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to introduce something like HelpOption.DefaultAliases and use it here for discoverability, etc.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would it be used by the end users? Currently to get the default aliases they can just do new HelpOption().Aliases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC Krzysztof or Jeremy started this discussion and the context was that it was not clear what aliases the HelpOption will use when created and added to the Command.

In #2107 I've made the config mutable and simply added xml docs to the HelpOption ctor:

/// <summary>
/// When added to a <see cref="Command"/>, it configures the application to show help when one of the following options are specified on the command line:
/// <code>
/// -h
/// /h
/// --help
/// -?
/// /?
/// </code>
/// </summary>
public HelpOption() : this("--help", new[] { "-h", "/h", "-?", "/?" })

I am expecting that this is going to solve the problem

# Conflicts:
#	src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt
#	src/System.CommandLine.Tests/Invocation/InvocationPipelineTests.cs
#	src/System.CommandLine/Builder/CommandLineBuilder.cs
#	src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs
#	src/System.CommandLine/CommandLineConfiguration.cs
@KalleOlaviNiemitalo
Copy link

If I wanted to specify the list of aliases of HelpOption (omitting "/h"), and set the maximum width, then what would be the most straightforward way to do both using this API? It seems UseHelp allows either of those customizations but not both. Should I avoid UseHelp altogether, and construct the HelpOption and HelpAction explicitly?

@adamsitnik adamsitnik merged commit 48faa68 into dotnet:main Mar 21, 2023
@adamsitnik adamsitnik deleted the helpCustomization branch March 21, 2023 19:55
@adamsitnik
Copy link
Member Author

adamsitnik commented Mar 22, 2023

If I wanted to specify the list of aliases of HelpOption (omitting "/h"), and set the maximum width

Currently it would be:

new HelpOption("--help", "-h")
{
    Action = new HelpAction()
    {
        Builder = new HelpBuilder($width)
    }
}

FWIW we are not done with our work on help customization. Most probably I won't have the time to work on it before we release a new preview package (beginning of April), I am afraid it will have to wait until June.

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.

3 participants