Skip to content

[WIP] Simplified parser building - #264

Merged
jonsequitur merged 6 commits into
dotnet:masterfrom
jonsequitur:simplified-parser-building
Oct 27, 2018
Merged

jonsequitur merged 6 commits into
dotnet:masterfrom
jonsequitur:simplified-parser-building

Conversation

@jonsequitur

@jonsequitur jonsequitur commented Oct 23, 2018 •

Copy link
Copy Markdown
Contributor

Over the course of this PR I'll be changing the Option, Command, Symbol, and other related types to become mutable so that they can be directly configured and composed to form a non-fluent parser building API. It's a work in progress and somewhat exploratory. Comments are welcome at every step.

This is working toward addressing #251.

@jonsequitur
jonsequitur requested a review from Keboo October 23, 2018 00:35
Comment thread src/System.CommandLine/Symbol.cs Outdated
public bool HasAlias(string alias) => _aliases.Contains(alias.RemovePrefix());
if (unprefixedAlias.Length > Name?.Length)
{
_name = unprefixedAlias;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably want to draw a distinction between overriding a value in _name that was set because of adding aliases and one that was explicitly set by the developer. If I explicitly set the Name I would not expect it to change simply because I added an alias that happens to have a longer character count.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thought. This is the kind of ambiguity that typically makes me avoid mutable models. For example, what if I set the name, and then assign an alias that's even longer?

Other options:

  • Make Name a purely computed value
  • Remove this property altogether.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always ben a bit uncomfortable with the Name just being another identifier. It seems special at least for help display and I think the programmer thinks of a name and aliases, not a name as another alias.

But I agree that if we are not going to make a name special, it should not lock special. Just not sure I agree yet with this outcome.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think this may open a can of worms. For example, this test currently fails. It looks like it should pass for Option but I would probably expect a different behavior for Command.

   [Fact]
        public void When_Name_is_set_without_a_prefix_then_the_prefix_is_valid_at_parse_time()
        {
            var option = new Option(new[] { "-a" }, "");

            option.Name = "bbb";

            var parser = new Parser(option);

            var result = parser.Parse("--bbb");

            result.Errors.Should().BeEmpty();
        }

@KathleenDollard KathleenDollard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the name question, I think this looks good. I'm happy to see it merge, assuming all tests pass, and continue talking on that issue.

@jonsequitur

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Ubuntu16.04 Release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants