Skip to content

Display help without requiring ParseArguments #281

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
Steve887 opened this issue Jan 20, 2016 · 5 comments
Open

Display help without requiring ParseArguments #281

Steve887 opened this issue Jan 20, 2016 · 5 comments

Comments

@Steve887
Copy link

I'm trying to print the help text for my options without having to force a parser error.

Currently, it seems the only way to print the help text is to call something like

Parser.Default.ParseArguments<Options>(new string[] { "verb", "--help" });

I see there's HelpText.AutoBuild but that seems to require a NotParsed result.

Is there a way to write the help text for an options class without having to parse arguments? Maybe something like HelpText.DisplayHelp<Options>?

@aggieben
Copy link

I also am interested in having the help command not generate an error which creates noise in my logging that is undesirable..

@nemec
Copy link
Collaborator

nemec commented Mar 23, 2016

I just noticed this snippet from the HelpTextTests unit test that just creates a fake result. Does this do what you were looking for?

var help = new HelpText { AddDashesToOption = true }
    .AddOptions(new NotParsed<Options_With_HelpText_And_MetaValue>(
        TypeInfo.Create(typeof(Options_With_HelpText_And_MetaValue)),
        Enumerable.Empty<Error>()));
Console.WriteLine(help.ToString());

It doesn't do the Copyright info or project name, but you can call the AddPreOptionsLine method on HelpText to add it in yourself.

@Steve887
Copy link
Author

@nemec The problem is NotParsed is an internal class so is not available during general usage.

@nemec
Copy link
Collaborator

nemec commented Mar 24, 2016

Ah, you're right. I was looking at the class but it's the constructor that's internal.

@robertkruis
Copy link

@Steve887, @nemec

Even though the NotParsed class is internal, you could create an instance by using reflection (although it's questionable if you should do so).
I created a gist with an extension method GetAutoBuildHelpText on the ParserResult class that will do exactly the same as the code in the unit test, except for the fact that it'll do this by using reflection.

You can find the gist here: https://gist.github.com/azforeversupporter/82b794ded5d16a390d89eb2071035388

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

No branches or pull requests

4 participants