CliFx with a list of objects command

I have an console application in c# that uses CliFx nuget package. This is an example of what I actually have:

[Command]
public class CommonXCommand : ICommand
{
    [CommandOption("property1")]
    public required string Property1 { get; init; }

    [CommandOption("list_obj")]
    public required IReadOnlyList<ObjCommand> ListObj { get; init; }

    [CommandOption("property2")]
    public required string Property2 { get; init; }

    public ValueTask ExecuteAsync(IConsole console)
    {
        throw new NotImplementedException();
    }
}

[Command]
public class ObjCommand : ICommand
{
    [CommandOption("property3")]
    public required string Property3 { get; init; }

    [CommandOption("property4")]
    public required string Property4 { get; init; }

    public ValueTask ExecuteAsync(IConsole console)
    {
        throw new NotImplementedException();
    }
}

I would like to have a command with options like property1/property2 and a list of a complex object like list_obj.

But, when I execute the command command_line.exe -property1 test1 --list_obj--property3 A --property4 B --list_obj --property3 c --property4 d --property2 test2 I got the error:

Unrecognized option(s):
–property3, –property4, –property3, –property4

Leave a Comment