Skip to content

Having only one verb will always execute the code path for this verb #471

Description

@Structed

If you have only one verb defined, but using an undefined verb will not output help, but will execute the code path for the only verb defined.

Reproduction Steps

Using CommandLineParser Version 2.5.0 and given this simple program:

    class Program
    {
        static int Main(string[] args)
        {
            return Parser.Default.ParseArguments<UpdateOptions>(args)
                .MapResult(
                    (UpdateOptions opts) => RunUpdateAndReturnExitCode(opts),
                    errs => 1);
        }

        private static int RunUpdateAndReturnExitCode(UpdateOptions opts)
        {
            Console.WriteLine("Running update verb");
            if (opts.Test)
            {
                return 1;
            }

            return 0;
        }
    }

    [Verb("update", HelpText = "Updates")]
    public class UpdateOptions
    {
        [Option(HelpText = "Whether this is a test")]
        public bool Test { get; set; }
    }

Expected Behaviour

Running this with a verb other than update should print the help text and point out, that the verb does not exist:

λ  dotnet run -- foo
Program 1.0.0
Copyright © 2019 Structed

ERROR(S):
  Verb 'foo' is not recognized.

  --help       Display this help screen.

  --version    Display version information.

Running with the verb help should display the help screen, and show the available verb:

λ  dotnet run -- help
Program 1.0.0
Copyright © 2019 Structed

  update     Updates

  help       Display more information on a specific command.

  version    Display version information.

Actual Behaviour

Running this with the correct verb update, will of course execute the path for this verb:

λ  dotnet run -- update
Running update verb

However, running this with the non existing verb foo will also (incorrectly) execute the path of the update verb:

λ  dotnet run -- foo
Running update verb

Using the Verb help does also execute the update verb's path:

λ  dotnet run -- help
Running update verb

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions