Skip to content

Properties backing arguments with multiple values not populated properly if short and long argument names are specified #15

Closed
@jpdillingham

Description

@jpdillingham

This issue will require a fairly significant rewrite of the Populate() method, as well as the GetArgumentProperties() method. The Parse() method should remain unchanged; it is designed to parse arguments as presented and has no concept of short or long argument names.

Arguments requiring multiple values are an edge case, and arguments requiring multiple values while also allowing the user to freely switch between short and long names in the same argument string are an extreme edge case.

I have no plans to implement this functionality at this time, however if someone would like to take it on I've included failing tests for array and List backed properties.

Failing Tests

TestClassWithListProperty

/// <summary>
///     Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
///     containing multiple instances of a list-backed argument, and containing a change from short to long names and back.
/// </summary>
[Fact]
public void PopulateWithNameChange()
{
    Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-l one --list two -l three"));

    Assert.Null(ex);
    Assert.Equal(3, List.Count);
    Assert.Equal("one", List[0]);
    Assert.Equal("two", List[1]);
    Assert.Equal("three", List[2]);
}

TestClassWithArrayProperty

/// <summary>
///     Tests the <see cref="Utility.CommandLine.Arguments.Populate(Type, string)"/> method with an explicit string
///     containing multiple instances of an array-backed argument, and containing a change from short to long names and back.
/// </summary>
[Fact]
public void PopulateWithNameChange()
{
    Exception ex = Record.Exception(() => CommandLine.Arguments.Populate(GetType(), "-a one --array two -a three"));

    Assert.Null(ex);
    Assert.Equal(3, Array.Length);
    Assert.Equal("one", Array[0]);
    Assert.Equal("two", Array[1]);
    Assert.Equal("three", Array[2]);
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions