Skip to content

--version with sub-commands fails with ParseResult.Errors #2628

Closed

Description

@ptr727

Testing with --help ok, but --version results in errors.

    protected virtual Task<int> Sandbox(string[] args)
    {
        RootCommand root = new("Test command");
        ParseResult result = root.Parse(["--version"]);
        if (result.Errors.Count > 0)
        {
            Log.Error("Commandline parsing failed: {Errors}", result.Errors);
            return Task.FromResult(1);
        }

        root = new("Test command");
        Option<string> option = new("--settingsfile") { Recursive = true };
        root.Options.Add(option);
        Command command = new("defaultsettings")
        {
            Description = "Create JSON configuration file using default settings",
            Options = { option },
        };
        command.SetAction(_ => 0);
        root.Subcommands.Add(command);
        result = root.Parse(["--version"]);
        if (result.Errors.Count > 0)
        {
            Log.Error("Commandline parsing with sub-command failed: {Errors}", result.Errors);
            return Task.FromResult(1);
        }

        return Task.FromResult(0);
    }
21:10:13 [ERR] <1> Commandline parsing with sub-command failed: ["Required command was not provided."]

Expect behavior to match that of --help with printing version info and no errors.

Activity

  1. self-assigned this
    on Jul 14, 2025
  2. added this to the 2.0.0-beta7 milestone on Jul 14, 2025
  3. added a commit that references this issue on Jul 15, 2025
    0f6fdd0
  4. added a commit that references this issue on Jul 16, 2025
    dbc3781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions