Skip to content
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