Commandline: Incorrect help text if AutoVersion = false

Created on 5 Mar 2019  路  16Comments  路  Source: commandlineparser/commandline

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

bug

Most helpful comment

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.

All 16 comments

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.

+1, we experiencing the same problem

Your .Net Fiddle helped me, and yes it does work. But I still don't think
it works very intuitively. In my view, when I set AutoVersion=false in
ParserSettings, then I expect "version" to be removed from help text as
well... automatically. But this is not how it works (I just tested in
2.5.0). I have to do like you show in the Fiddle and add all the
HelpText.AutoBuild code and specificly set AutoVersion=false just to
suppress it from being shown i help text. So what I'm saying is, that I
have to set AutoVersion=false in both ParserSettings and HelpText.AutoBuild
for it to work. I feel that is a bug.

On Sun, Jun 23, 2019 at 11:21 PM Mohamed Hassan notifications@github.com
wrote:

I test the custom help in v2.5.0 with AutoVersion = false and
`AutoHelp=false' and Version /Help are not displayed.
This means that it works fine in v2.5.0
Can you check this online Demo https://dotnetfiddle.net/vk7WEO with
example how to configure HelpText

@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.

@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

@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 :)

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

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

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; }
}

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);  

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.

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

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.

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.

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ppumkin picture ppumkin  路  4Comments

Silverwing1983 picture Silverwing1983  路  4Comments

Valinwolf picture Valinwolf  路  3Comments

IB38 picture IB38  路  4Comments

ericnewton76 picture ericnewton76  路  5Comments