Repository navigation
Simplified, mutable parser config - #252
Conversation
|
|
||
| namespace System.CommandLine | ||
| { | ||
| public interface ISymbol : ISuggestionSource |
There was a problem hiding this comment.
Does ISymbol need to derive from ISuggestionSource? Would it be better to separate these and have Symbol implement each separately?
There was a problem hiding this comment.
It doesn't, but for what it's worth, Command and Option are both suggestion sources, and I'm thinking that Argument (which is also a suggestion source) should also become an ISymbol.
|
|
||
| bool HasAlias(string alias); | ||
|
|
||
| bool HasRawAlias(string alias); |
There was a problem hiding this comment.
If I was working with this interface I would wonder what the difference was between these methods and simply doing a .Contains() on the collection directly.
There was a problem hiding this comment.
.Contains() gets a bit complicated when you take prefixes into account.
There was a problem hiding this comment.
For the raw aliases I agree, but isn't the only difference between the two collections whether the prefix is present?
There was a problem hiding this comment.
Yes. HasAlias strips the prefix and compares against the existing aliases without their prefixes. It doesn't require the caller to know which prefixes are configured.
There was a problem hiding this comment.
Would it be clearer to replace the term "raw alias" with "alias with prefix" or something to that effect?
|
|
||
| ICommand ISymbol.Parent => Parent; | ||
|
|
||
| ISymbolSet ISymbol.Symbols => Symbols; |
There was a problem hiding this comment.
Is the expectation to change the types of the properties above so we don't need these explicit implementations?
There was a problem hiding this comment.
ISymbol is the readable surface. Symbol will become mutable by adding setters, a default constructor, etc.
|
test this please |
|
I am not familiar with these basic types, which is a good thing here -- I guess we want the user to create mutable objects that implement ISymbol and IOption etc.
_3. to config a tree we need to create 2 objects first and then let child to point to parent right? I think It is not very intuitive, but still okish. i get it after looking at the signature for a while |
KathleenDollard
left a comment
There was a problem hiding this comment.
31 files led me to postpone reviewing for a couple of days - sorry about that.
My comments are for clarity on my part.
I think there are a boatload of tweaks to consider - like clarity in raw aliases that came up. But I strongly feel that this is the right direction overall and we should merge ASAP.
| bool enablePositionalOptions = false, | ||
| ValidationMessages validationMessages = null, | ||
| ResponseFileHandling responseFileHandling = default(ResponseFileHandling), | ||
| ResponseFileHandling responseFileHandling = default, |
There was a problem hiding this comment.
Are we committed to C# 7.3 (or did I forget where this came in).
I think that is dandy, just want it to be conscious decision
| var hasOptionHelp = command.Symbols | ||
| .OfType<Option>() | ||
| .Any(symbolDef => symbolDef.HasHelp); | ||
| var hasOptionHelp = command.Children |
There was a problem hiding this comment.
I like how the change to "Children" works in code like this.
| { | ||
| public interface ICommand : ISymbol | ||
| { | ||
| bool TreatUnmatchedTokensAsErrors { get; } |
There was a problem hiding this comment.
Is this applicable to all commands or just the root/entry point?
There was a problem hiding this comment.
To all commands. In dotnet, there are different commands with different rules around this, which is where this came from.
|
|
||
| namespace System.CommandLine | ||
| { | ||
| public interface IOption : ISymbol |
There was a problem hiding this comment.
I'm a little surprised these interfaces are empty. Is that the WIP state?
| { | ||
| IReadOnlyCollection<string> Aliases { get; } | ||
|
|
||
| IReadOnlyCollection<string> RawAliases { get; } |
There was a problem hiding this comment.
At the moment, the applicability of raw alias to commands isn't clear. Agree that with lower comments that this is an area to document, although I hope app models largely hide this.
There was a problem hiding this comment.
I suspect RawAliases can become an internal implementation detail and we can collapse the HasAlias and HasRawAlias methods down to something like:
bool HasAlias(string alias, string prefix = null);
I'm not sure how clear the intention is there. The gist is that HasAlias tends to be an end-user use case (i.e. don't make me think about prefixes when looking at parse results) and HasRawAlias tends to be an internal use-case (i.e. pre-compute all of the valid tokens and put them in a hashset for more efficient lookup during parse.)
| if (handler != null) | ||
| invocations.Add(async (invocationContext, next) => | ||
| { | ||
| if (invocationContext |
There was a problem hiding this comment.
What else might it be?
There was a problem hiding this comment.
It could be a different implementation of ICommand, though we have no intention of creating another implementation at the moment.
|
@dotnet-bot test Ubuntu16.04 Release |
This is a working sketch of a simpler, mutable parser configuration API in pursuit of #251. Please focus comments on the API surface. Implementation details will be cleaned up once we get to an API we're happier with.