Skip to content

Help Text Displays 'help' Option/Verb if AutoHelp is 'False' #455

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

Closed
x789 opened this issue Jun 6, 2019 · 4 comments
Closed

Help Text Displays 'help' Option/Verb if AutoHelp is 'False' #455

x789 opened this issue Jun 6, 2019 · 4 comments
Labels

Comments

@x789
Copy link

x789 commented Jun 6, 2019

Description

If I configure the parser to not support the implicit option/verb 'help', the help text still contains the option/verb.
(This is possibly related to #414)

Expected Behavior

I expect that the option/verb is not displayed.

Environment

  • .NET Core 2.2 Application
  • CommandLineParser Nuget Package 2.5.0

How to Reproduce

  1. Configure the parser:
    var parser = new Parser(config =>
      {
        config.AutoHelp = false;
        config.HelpWriter = Console.Out;
      });
    var parserResult = parser.ParseArguments ...
    
  2. Execute your program with --help

    ERROR(S):
    Verb '--help' is not recognized.

    --help Display this help screen.

    --version Display version information.

@x789
Copy link
Author

x789 commented Jun 7, 2019

I investigated this issue and found a reason for this behavior. The parser-settings are not propagated to the method (HelpText.AutoBuild) that actually builds the help text.
Therefore, I think that #414 and #455 have the same origin.

I should be able to provide a patch in the next days...

@x789
Copy link
Author

x789 commented Jul 1, 2019

Closed (Reason)

@x789 x789 closed this as completed Jul 1, 2019
@moh-hassan
Copy link
Collaborator

moh-hassan commented Jul 1, 2019

@x789

The AutoHelp /AutoVersion properties of Parser for disabling AutoHelp /AutoVersion generation.
The AutoHelp /AutoVersion properties of HelpText for hiding/showing --help/--version
They have the same names but have different purpose.

So to hide --help/--version option , these properties should be false in both Parser and HelpText

var parser = new CommandLine.Parser(with=>
{

					with.AutoHelp=false; //disable AutoHelp Generation
					with.AutoVersion=false; //disable AutoVersion Generation						
				}); 

                          //use HelText to generate help without --help/--version options

                           var helpText = HelpText.AutoBuild(Result, h =>
						{					
							//this is working ONLY when parser  AutoHelp /AutoVersion =false
            // it may better if renamed ShowHelp/ShowVersion
							h.AutoHelp=false; //hide --help option
							h.AutoVersion=false;		//hide --version option									
							return h;
						}, 
						e =>e);

It may be better if these properties are renamed in HelpText to be: ShowHelp/ShowVersion

How To show help/version screen

In WithNotParsed method you should catch the error of type "UnknownOptionError" and based on the Token "help" or "version" show your custom help/version screen

@moh-hassan
Copy link
Collaborator

This issue is resolved in v2.6.0
Show example

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

No branches or pull requests

2 participants