Command-line-api: Bug: Second string argument gets first string argument's value

Created on 15 Apr 2020  路  6Comments  路  Source: dotnet/command-line-api

Hello,

DragonFruit looks sweet and I look forward to using it someday. Thank you!

I think I'm seeing a bug in System.CommandLine,DragonFruit. Full details below. Please let me know if I can help with finding and fixing.

Environment:

OS: Windows 10 Professional
.Net Core: 3.1.201
IDE: Visual Studio 2019 v16.5.3
System.CommandLine,DragonFruit: 0.3.0-alpha.20213.1

Reproduction:

https://github.com/urig/dragonfruit-repro

Steps to reproduce:

  1. In Visual Studio 2019, create a new .Net Core Console Application project.
  2. Add a NuGet dependency on DargonFruit:
    <PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20213.1" />

  3. Change the Main() to accept two string arguments and print them:

    static void Main(string foo, string bar)
    {
        Console.WriteLine($"foo is {foo}");
        Console.WriteLine($"bar is {bar}");
    }
    
  4. Build and run the Console Application with the foo argument:
    ConsoleApplication1.exe --foo foo

Expected behavior:

string foo should be set to 'foo' and string bar should be set to null, printing:

foo is foo
bar is

Actual behavior

string foo is set to 'foo' and string bar is also set to 'foo', printing:

foo is foo
bar is foo

bug duplicate

All 6 comments

Same behaviour also with
rootCommand.Handler = CommandHandler.Create<string, string>(Export);

It seems, that the types are checked only.

Fixed by #853

This appears to be the same issue as #854. Please try the latest release from nuget.org and let us know if you're still seeing the issue.

I tried writing a unit test that would detect the actual behavior, in (CommandLineTests.cs):

    [Fact]
    public async Task It_executes_method_with_two_strings()
    {
        int exitCode = await CommandLine.InvokeMethodAsync(
            new[] { "--first", "Bruce" },
            TestProgram.TestMainWithTwoStringsMethodInfo,
            null,
            _testProgram,
            _terminal);
        exitCode.Should().Be(0);
        // expected actual value to be "Bruce Bruce", but it isn't and this passes:
        _terminal.Out.ToString().Should().Be("Bruce ");
    }

But the behavior is not reproduced when I run it. What am I missing?

Which version are you using?

I can confirm this is fixed for me in 0.3.0-alpha.20214.1. Joy 馃榾

Thank you @jonsequitur @Keboo 馃檹馃徎

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jnm2 picture jnm2  路  6Comments

SirJosh3917 picture SirJosh3917  路  3Comments

pjmagee picture pjmagee  路  7Comments

rgueldenpfennig picture rgueldenpfennig  路  4Comments

AlgorithmsAreCool picture AlgorithmsAreCool  路  6Comments