Skip to content

Boolean arguments on Parent class are not set #2

@bryanbcook

Description

@bryanbcook

I have the following setup:

public class CommandArgs
{
    [Parameter("verbose", Required = Required.No)
    public bool Verbose { get; set; }

    [Command("go")]
    public GoCommand GoCmd { get; set; }
}

public class GoCommand : ICommand
{
     [Parameter("x")]
     public string X { get; set; }

     public void Execute(object parent)
     {
         var globalArgs = (CommandArgs)parent;
         
         Console.Writeline(globalArgs.Verbose); // <-- always false
     }
}

Expected: the value of the CommandArgs.Verbose should be set to true when --verbose is supplied on the command-line.
Actual: the value is ignored.

If I change this code and move the Verbose flag to the GoCommand class, it does get picked up correctly.

I'm using .NET Core 5 in Visual Studio 2022.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions