Skip to content

fix #1647 #1649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/System.CommandLine.Tests/Binding/TypeConversionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
Expand Down Expand Up @@ -221,6 +221,21 @@ public void Nullable_bool_parses_as_null_when_the_option_has_not_been_applied()
.Be(null);
}

[Fact] // https://github.com/dotnet/command-line-api/issues/1647
public void Generic_option_bool_parses_when_passed_to_non_generic_GetValueForOption()
{
var option = new Option<bool>("-b");

var cmd = new RootCommand
{
option
};

var parseResult = cmd.Parse("-b");

parseResult.GetValueForOption((Option)option).Should().Be(true);
}

[Fact]
public void By_default_an_option_with_zero_or_one_argument_parses_as_the_argument_string_value()
{
Expand Down
6 changes: 3 additions & 3 deletions src/System.CommandLine/Binding/ArgumentConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
Expand Down Expand Up @@ -204,8 +204,8 @@ internal static ArgumentConversionResult ConvertIfNeeded(
toType,
successful.Value,
symbolResult.LocalizationResources),

NoArgumentConversionResult _ when toType == typeof(bool) || toType == typeof(bool?) =>
NoArgumentConversionResult _ when conversionResult.Argument.ValueType == typeof(bool) || conversionResult.Argument.ValueType == typeof(bool?) =>
Success(conversionResult.Argument, true),

NoArgumentConversionResult _ when conversionResult.Argument.Arity.MinimumNumberOfValues > 0 =>
Expand Down