Skip to content
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

Generate Help on a specific verb #901

Open
sybaris opened this issue Sep 18, 2023 · 4 comments
Open

Generate Help on a specific verb #901

sybaris opened this issue Sep 18, 2023 · 4 comments

Comments

@sybaris
Copy link

sybaris commented Sep 18, 2023

Describe the bug
When I call my program with the following arguments : "help verb1", I expect that the help for this specific verb was displayed. But instead, the help for all verbs are displayed.

To Reproduce

    [Verb("Verb1", HelpText ="Help Verb1")]
    internal class Verb1
    {
        [Option(Required = true, HelpText = "Help MyOption1")]
        public string MyOption1 { get; set; }
    }

    [Verb("Verb2",HelpText = "Help Verb2")]
    internal class Verb2
    {
        [Option(Required = true, HelpText = "Help MyOption2")]
        public string MyOption2 { get; set; }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            var parser = new Parser(config => config.HelpWriter = null);
            var parserResult = parser.ParseArguments<
                Verb1,
                Verb2
            >
            (args);

            parserResult.MapResult(
                 (Verb1 options) => { return 0; },
                 (Verb2 options) => { return 0; },
                 errors => {
                     DisplayHelp(parserResult, errors);
                     return 0;
                 });

            Console.ReadKey();
        }

        static void DisplayHelp<T>(ParserResult<T> result, IEnumerable<Error> errs)
        {
            var helpText = HelpText.AutoBuild(result, h =>
            {
                h.AdditionalNewLineAfterOption = false;
                h.Heading = "Myapp 2.0.0-beta"; //change header
                h.Copyright = "Copyright (c) 2019 Global.com"; //change copyright text
                return HelpText.DefaultParsingErrorsHandler(result, h);
            }, e => e, verbsIndex:true);
            Console.WriteLine(helpText);
        }
    }

When I excecute this with the command line "MyApp.exe help verb1"
The actual result is :
image

Expected behavior
This display :
Verb2 Help Verb1
MyOption2 Help MyOption2

@gfs
Copy link

gfs commented Sep 18, 2023

Verbs are case sensitive. It looks like you're using verb1 on the command line, but the program expects Verb1.

@sybaris
Copy link
Author

sybaris commented Sep 20, 2023

Hi @gfs
Thanks for your answer.
But I have the same behavior when I use the correct case Verb1
And also when I have config.CaseSensitive = false; , I have the same behavior...

@gfs
Copy link

gfs commented Oct 9, 2023

@sybaris

Try removing this part , e => e, verbsIndex:true.

Image

@sybaris
Copy link
Author

sybaris commented Oct 10, 2023

Hi,
Exact.
Thanks for you answer.

Note that I have this code because it's a copy paste of wiki

Regards
Sybaris

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

2 participants