Skip to content

[Feature request] Let HelpText.AutoBuild method populate HelpText instance according to parser settings #595

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

Open
elgonzo opened this issue Mar 12, 2020 · 0 comments

Comments

@elgonzo
Copy link

elgonzo commented Mar 12, 2020

Currently, when setting AutoHelp and/or AutoVersion for the parser to false, the HelpText.AutoBuild method does not acknowledge those parser settings for the respective HelpText properties, thus forcing the user to repeat setting those settings for HelpText.

Right now, i have to write something like that:

    static void Main(string[] args)
    {
        using (var cmdLineParser = new Parser(settings => { settings.AutoHelp = false; settings.AutoVersion = false; }))
        {
            var parserResult = cmdLineParser.ParseArguments<SomeOptionsType>(args);
            parserResult
                .WithNotParsed(errors => DisplayHelp(parserResult, errors))
                .WithParsed(Execute);
        }
    }

    static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
    {
        var helpText = HelpText.AutoBuild(
            result,
            h =>
                {
                    h.AutoHelp = false;
                    h.AutoVersion = false;
                    return h;
                }
        );
        Console.WriteLine(helpText);
    }

Note how my code for the DisplayHelp method is forced to again set the AutoHelp and AutoVersion settings for the HelpText to false (since they default to true, despite the respective parser settings being set to false).

Ideally, it would be nice if HelpText.AutoBuild could initialize the HelpText instance with the values from any appropriate settings of the parser used to produce the ParserResult.

(Related discussion: #414)

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

No branches or pull requests

2 participants