diff --git a/src/CommandLine/Core/Tokenizer.cs b/src/CommandLine/Core/Tokenizer.cs index c588a98f..00314a7c 100644 --- a/src/CommandLine/Core/Tokenizer.cs +++ b/src/CommandLine/Core/Tokenizer.cs @@ -68,7 +68,7 @@ public static Result, Error> ExplodeOptionList( Tuple.Create(-1, '\0'))).SkipWhile(x => x.Item1 < 0).Memoize(); var exploded = tokens.Select((t, i) => - replaces.FirstOrDefault(x => x.Item1 == i).ToMaybe() + replaces.FirstOrDefault(x => x.Item1 == i && t.Tag == TokenType.Value).ToMaybe() .MapValueOrDefault(r => t.Text.Split(r.Item2).Select(Token.Value), Enumerable.Empty().Concat(new[] { t }))); diff --git a/tests/CommandLine.Tests/Unit/Issue420Tests.cs b/tests/CommandLine.Tests/Unit/Issue420Tests.cs new file mode 100644 index 00000000..cad06c46 --- /dev/null +++ b/tests/CommandLine.Tests/Unit/Issue420Tests.cs @@ -0,0 +1,50 @@ +using FluentAssertions; +using System.Collections.Generic; +using Xunit; + +namespace CommandLine.Tests.Unit +{ + public class Issue420Tests + { + // Test method (xUnit) which fails + [Fact] + public void parsing_of_enumerable_types_with_separator_chars_should_validate_value_is_present() + { + string[] args = { "-j", "1", "--categories", "--flag" }; + + ParserResult parsedOptions = Parser.Default.ParseArguments(args); + + parsedOptions.Tag.Should().Be(ParserResultType.NotParsed); + + ParserResult parsedOptionsWithSeparator = Parser.Default.ParseArguments(args); + + parsedOptionsWithSeparator.Tag.Should().Be(ParserResultType.NotParsed); + } + + // Options + internal class Options + { + [Option('f', "flag", HelpText = "Flag")] + public bool Flag { get; set; } + + [Option('c', "categories", Required = false, HelpText = "Categories")] + public IEnumerable Categories { get; set; } + + [Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")] + public int JobId { get; set; } + } + + // Options + internal class OptionsWithSeparator + { + [Option('f', "flag", HelpText = "Flag")] + public bool Flag { get; set; } + + [Option('c', "categories", Required = false, Separator = ',', HelpText = "Categories")] + public IEnumerable Categories { get; set; } + + [Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")] + public int JobId { get; set; } + } + } +}