Repository navigation
[WIP] Simplified parser building - #264
Conversation
| public bool HasAlias(string alias) => _aliases.Contains(alias.RemovePrefix()); | ||
| if (unprefixedAlias.Length > Name?.Length) | ||
| { | ||
| _name = unprefixedAlias; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Namea purely computed value - Remove this property altogether.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
@dotnet-bot test Ubuntu16.04 Release |
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.