Command-line-api: Allow an option to have multiple values assigned using a comma-separated list

Created on 10 May 2018  路  8Comments  路  Source: dotnet/command-line-api

Update the lexer to support specifying an option that supports more than one argument using a comma-separated list:
e.g. DisplayTable -column FirstColumn, SecondColumn
Whitespace around the comma is allowed.

Area-API Area-Parser and Model Binder needs documentation

All 8 comments

Regex patterns are definitely not my forte, so if someone else sees this and wants it done faster than I can do, feel free to take it (and if possible, I'd love to pair on it). I'll make sure to push any tests I write to a WIP PR.

@PandaMagnus, the lexer isn't using a regex, but the tokenizer is. This feature would impact both, assuming spaces between comma-grouped items are allowed as in @MarkMichaelis's example.

@jonsequitur Understood. I'll make sure to take a look at the lexer as well. If I get in over my head I'll pair or set it aside.

I expect that the lexer and core parse operations will need an overhaul at some point. The implementation isn't elegant and the performance needs to be improved. That might be the kind of thing that we undertake first, with improvements like this in mind, before adding support for additional cases.

In addition to , as a split delimiter, I've seen examples of | and ;, so making the actual split delimiter configurable by the user would be a good idea.

@srsaggam

@CESARDELATORRE

736 adds support for easier custom argument parsing, so enabling custom split delimiters can be done like this:

            [Fact]
            public void custom_parsing_of_sequence_value_from_an_argument_with_one_token()
            {
                var argument = new Argument<IEnumerable<int>>(result =>
                {
                    result.Value = result.Tokens.Single().Value.Split(",").Select(int.Parse);

                    return true;
                });

                argument.Parse("1,2,3")
                        .FindResultFor(argument)
                        .GetValueOrDefault()
                        .Should()
                        .BeEquivalentTo(new[] { 1, 2, 3 });
            }
Was this page helpful?
0 / 5 - 0 ratings