Fix #420 - Check for value token before expanding enumerable types with separator char#672
Open
wo-roberts wants to merge 1 commit intocommandlineparser:developfrom
Open
Fix #420 - Check for value token before expanding enumerable types with separator char#672wo-roberts wants to merge 1 commit intocommandlineparser:developfrom
wo-roberts wants to merge 1 commit intocommandlineparser:developfrom
Conversation
…umerable types with separator char
Contributor
|
I don't think this is quite the right solution. I think in addition to checking if the token to be exploded is a Value, we also need to check if the previous token is a Name. I'll try to create a unit test that proves that. BTW, I'm currently working on a fix for #396 that looks like it's going to end up fixing #420 at the same time, so once that PR is submitted I'll link to it from this one as well. |
Contributor
|
Here's a unit test that fails with this PR, but works if you also check that the previous token is a Name: [Fact]
public static void Values_with_same_name_as_sequence_option_do_not_cause_later_values_to_split_on_separators()
{
var args = new[] { "c", "x,y" };
var tokensExpected = new[] { Token.Value("c"), Token.Value("x,y") };
var typeInfo = typeof(OptionsWithSeparator);
var specProps = typeInfo.GetSpecifications(pi => SpecificationProperty.Create(
Specification.FromProperty(pi), pi, Maybe.Nothing<object>()))
.Select(sp => sp.Specification)
.OfType<OptionSpecification>();
var tokenizerResult = Tokenizer.ConfigureTokenizer(StringComparer.InvariantCulture, false, false)(args, specProps);
var tokens = tokenizerResult.SucceededWith();
tokens.Should().BeEquivalentTo(tokensExpected);
}
internal class OptionsWithSeparator
{
[Option('f', "flag", HelpText = "Flag")]
public bool Flag { get; set; }
[Option('c', "categories", Required = false, Separator = ',', HelpText = "Categories")]
public IEnumerable<string> Categories { get; set; }
[Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")]
public int JobId { get; set; }
} |
Contributor
|
47618e0 (part of #684) is a better fix, which fixes the unit test in #672 (comment) that fails with this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.