Skip to content

Command line options inherited from branch settings are not being bound. #1612

@robcao

Description

@robcao

Information

  • OS: Windows
  • Version: 0.49.1
  • Terminal: Windows Terminal

Describe the bug
A clear and concise description of what the bug is.

I believe this is the same bug as mentioned in #428, where command options from parent settings aren't being taken into account / parsed.

I'm trying to pass in command options that are stored in a parent settings class, but these command options all appear to be ignored.

using Spectre.Console.Cli;

namespace Repro;

public class BranchSettings : CommandSettings
{
	[CommandOption("--my-value")]
	public string MyValue { get; set; } = string.Empty;
}

public class BranchedCommandSettings : BranchSettings
{
}

public class BranchedCommand : Command<BranchedCommandSettings>
{
	public override int Execute(CommandContext context, BranchedCommandSettings settings) => 0;
}

And my program file:

using Repro;
using Spectre.Console.Cli;

CommandApp app = new();

app.Configure(config =>
{
	config.ValidateExamples();
	config.AddBranch<BranchSettings>("branch", user =>
	{
		user.SetDescription("Branch.");

		user.AddCommand<BranchedCommand>("command")
			.WithDescription("Command under a branch.")
			.WithExample("branch", "command", "--my-value", "abc");
	});
});

return app.Run(args);

To Reproduce

I have created a minimum reproducible example here: https://github.com/robcao/spectre-console-branch-inheritance

To reproduce, download the example, navigate to the repro directory, and run dotnet run.

The application fails with the following exception:

dotnet run

Error: Validation of examples failed.

Error: Unknown option 'my-value'.

       branch command --my-value abc
                      ^^^^^^^^^^ Unknown option

Expected behavior
A clear and concise description of what you expected to happen.

I expect command options defined on parent setting classes to be bound.

When running dotnet run branch command --my-value abc, I would expect the following:

  • ValidateExamples should not fail
  • In the BranchedCommand .Execute method, the value of BranchedCommandSettings.MyValue should be abc.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

Labels

⭐ top bugTop bug.area-CLICommand-Line InterfacebugSomething isn't working

Type

Projects

Status

Todo 🕑

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions