Skip to content

Incorrect help text if AutoVersion = false #414

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
TheNybbler opened this issue Mar 5, 2019 · 16 comments
Closed

Incorrect help text if AutoVersion = false #414

TheNybbler opened this issue Mar 5, 2019 · 16 comments
Labels

Comments

@TheNybbler
Copy link

If you configure the Parser with ParserSettings.AutoVersion=false, the help text still displays the line:
--version Display version information.

@pihalve
Copy link

pihalve commented Mar 10, 2019

Just experienced the exact same. Would be nice if this could be fixed. I tried fiddling with customization of help texts to see if I could suppress the version help text, but there is almost no documentation of help text customization - at least not enough to make it useful for people who are not extremely familiar with the CommandLineParser source code.

@terotgut
Copy link

+1, we experiencing the same problem

@pihalve
Copy link

pihalve commented Jun 24, 2019 via email

@moh-hassan
Copy link
Collaborator

@pihalve , Yes, configuration of AutoHelp should be in one Place and I consider it a bug.
There are PR(s) in progress to fix this bug.

@moh-hassan
Copy link
Collaborator

@pihalve
The objective of AutoHelp / AutoVersion is different than Show/hide help
The original PR with this feature is #256

Added AutoHelp and AutoVersion properties to control adding of implicit 'help' and 'version' options/verbs

Do you mean :

  • Hide the option help / version from help text and disable user from using --help / --version
  • Hide the option help / version from help text and enable user from using --help / --version
  • Other objective

@pihalve
Copy link

pihalve commented Jun 25, 2019

@moh-hassan Yeah, well I mean configuring it in just one place, so when I have something like:
var parser = new Parser(with=>
{
// Configure Parser
with.AutoVersion = false;
});
Then I would expect it to be disabled and removed from help text, just like described in first post of this issue.
What I was trying to say earlier was that if I do something like in your fiddle, then it can actually work, but I see it more like a work-around. So I'll just have to wait until it's fixed :)

@moh-hassan
Copy link
Collaborator

moh-hassan commented Jul 1, 2019

@pihalve
Have a look to the wiki documentation page that explain the purpose of AutoHelp/AutoVersion
How to hide --help/--version

@moh-hassan
Copy link
Collaborator

This issue is resolved in V2.6.0
The Custome help usage is:

           var parser = new CommandLine.Parser(with=>
				{
				  with.HelpWriter = null;
				}); 
	var	parserResult = parser.ParseArguments<Options>(args);				
	 parserResult.WithNotParsed(errs =>
					{
						var helpText = HelpText.AutoBuild(parserResult, h =>
						{						
							h.AutoHelp=false; //hide --help
							h.AutoVersion=false; //hide --version		
							return h;
						}, 
						e =>e);
					   Console.WriteLine(helpText);
					});
                 }

}

Try it online

@loop-evgeny
Copy link

This is not fixed in v2.6.0. It still shows --version in the output of --help even if AutoVersion = false.

Simple repro code:

// @nuget: CommandLineParser -Version 2.6.0

using System;
using System.Collections.Generic;
using CommandLine;
				
public class Program
{
	public static void Main()
	{
		var parser = new Parser(ps =>
								{
									ps.HelpWriter = Console.Out;
									ps.AutoVersion = false; // Still shows --version
								});
	    var result = parser.ParseArguments<Options>(new[] {"--help"});
		Console.WriteLine(result.Tag);
		result.WithParsed<Options>(	o => { Console.WriteLine("aflag = " + o.AFlag); })
              .WithNotParsed(errs => HandleParseError(errs));
	
	}
	static void HandleParseError(IEnumerable<Error> errs)
     {
       errs.Dump();
     }
}
	

class Options
{
[Option("aflag", Required = false)]
public bool AFlag { get; set; }
}

@moh-hassan
Copy link
Collaborator

Hiding --version and --help is configured in HelpText not in the Parser
See How To in wiki

This is working in v2.6.0:

 helpText=  HelpText.AutoBuild(result, h =>
			 {			    
				 h.AutoVersion =false; //hide --version
				 h.AutoHelp =false;	// hide --help		  
		               return HelpText.DefaultParsingErrorsHandler(result, h);
			 }, e=>e);	

@loop-evgeny
Copy link

OK, so if I understand correctly, ParserSettings.AutoVersion = false prevents --version from working, but the user also need to set HelpText.AutoVersion = false to prevent it from being shown in --help? That seems really confusing. Why would you ever want to show a command line argument that's not supported? I would expect that an option that is disabled is not shown in --help output either.

@moh-hassan
Copy link
Collaborator

@loop-evgeny
What is supposed to be done taking into account that version and help is standard command in Gnu ?

@loop-evgeny
Copy link

Well, I would expect that if --version is disabled then it doesn't show up in the help. I don't see how it being standard changes that - it's still unhelpful to tell the user there is an option they can use when they actually cannot use it.

@moh-hassan
Copy link
Collaborator

Do you think that we remove AutoHelp /AutoVersion from ParserSettings(or at least be internal to avoid failure of some test cases) to continue going in the standard Gnu way.

@loop-evgeny
Copy link

No, I think they're useful. For my application --version is meaningless and I don't care about following GNU standards, but AutoHelp is still useful, so I want to set AutoVersion = false, but AutoHelp = true.

@moh-hassan
Copy link
Collaborator

Just for information, this is the original PR that implement the feature and its reference to issues.
AFAIK, HelpText class is not aware of ParserSettings.

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

5 participants