commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Display help without requiring ParseArguments

Open ericnewton76 opened this issue 8 years ago • 6 comments

Issue by Steve887 Wednesday Jan 20, 2016 at 01:30 GMT Originally opened as https://github.com/gsscoder/commandline/issues/281


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>?

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by aggieben Friday Jan 22, 2016 at 21:39 GMT


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

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by nemec Wednesday Mar 23, 2016 at 23:46 GMT


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.

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by Steve887 Thursday Mar 24, 2016 at 00:07 GMT


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

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by nemec Thursday Mar 24, 2016 at 00:39 GMT


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

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by azforeversupporter Wednesday Aug 03, 2016 at 09:39 GMT


@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

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

This is still a problem and would make the usage of this library a lot better. I have some business specific validation rules to perform and these business rules are document in the help message. So when the parsed values are invalid, I'd like to give an error message that says what went wrong and display the help/usage. Would love to see this get fixed.

th3oth3rjak3 avatar Aug 16 '24 23:08 th3oth3rjak3