diff --git a/src/CommandLine/Core/Tokenizer.cs b/src/CommandLine/Core/Tokenizer.cs index ba6f1ef5..c588a98f 100644 --- a/src/CommandLine/Core/Tokenizer.cs +++ b/src/CommandLine/Core/Tokenizer.cs @@ -135,6 +135,12 @@ private static IEnumerable TokenizeShortName( string value, Func nameLookup) { + //Allow single dash as a value + if (value.Length == 1 && value[0] == '-') + { + yield return Token.Value(value); + yield break; + } if (value.Length > 1 && value[0] == '-' && value[1] != '-') { var text = value.Substring(1); diff --git a/tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs b/tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs index 32d79b4f..f14eea51 100644 --- a/tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs +++ b/tests/CommandLine.Tests/Unit/Core/TokenizerTests.cs @@ -123,6 +123,26 @@ public void Should_return_error_if_option_format_with_equals_is_not_correct() Assert.Equal(ErrorType.BadFormatTokenError, tokens.First().Tag); Assert.Equal(ErrorType.BadFormatTokenError, tokens.Last().Tag); } + + + [Theory] + [InlineData(new[] { "-a", "-" }, 2,"a","-")] + [InlineData(new[] { "--file", "-" }, 2,"file","-")] + [InlineData(new[] { "-f-" }, 2,"f", "-")] + [InlineData(new[] { "--file=-" }, 2, "file", "-")] + [InlineData(new[] { "-a", "--" }, 1, "a", "a")] + public void single_dash_as_a_value(string[] args, int countExcepted,string first,string last) + { + //Arrange + //Act + var result = Tokenizer.Tokenize(args, name => NameLookupResult.OtherOptionFound, token => token); + var tokens = result.SucceededWith().ToList(); + //Assert + tokens.Should().NotBeNull(); + tokens.Count.Should().Be(countExcepted); + tokens.First().Text.Should().Be(first); + tokens.Last().Text.Should().Be(last); + } } }