Skip to content

Simplified, mutable parser config - #252

Merged
jonsequitur merged 2 commits into
dotnet:masterfrom
jonsequitur:simplified-parser-config
Oct 16, 2018
Merged

jonsequitur merged 2 commits into
dotnet:masterfrom
jonsequitur:simplified-parser-config

Conversation

@jonsequitur

Copy link
Copy Markdown
Contributor

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.

Comment thread src/System.CommandLine/ISymbol.cs Outdated

namespace System.CommandLine
{
public interface ISymbol : ISuggestionSource

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.

Does ISymbol need to derive from ISuggestionSource? Would it be better to separate these and have Symbol implement each separately?

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.

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);

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.

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.

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.

.Contains() gets a bit complicated when you take prefixes into account.

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.

For the raw aliases I agree, but isn't the only difference between the two collections whether the prefix is present?

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.

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.

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.

Would it be clearer to replace the term "raw alias" with "alias with prefix" or something to that effect?

Comment thread src/System.CommandLine/Symbol.cs Outdated

ICommand ISymbol.Parent => Parent;

ISymbolSet ISymbol.Symbols => Symbols;

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.

Is the expectation to change the types of the properties above so we don't need these explicit implementations?

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.

ISymbol is the readable surface. Symbol will become mutable by adding setters, a default constructor, etc.

@jonsequitur

Copy link
Copy Markdown
Contributor Author

test this please

@wli3

wli3 commented Oct 12, 2018

Copy link
Copy Markdown

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.

  1. I know we had a hard time to find a name for symbol, but still, it is difficult for user to understand what it is by reading the interface definition

  2. ISymbolSet Symbols { get; } what is symbols field in symbol? itself?

_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 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.

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,

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.

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

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.

Yes.

var hasOptionHelp = command.Symbols
.OfType<Option>()
.Any(symbolDef => symbolDef.HasHelp);
var hasOptionHelp = command.Children

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 like how the change to "Children" works in code like this.

{
public interface ICommand : ISymbol
{
bool TreatUnmatchedTokensAsErrors { get; }

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.

Is this applicable to all commands or just the root/entry point?

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.

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

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'm a little surprised these interfaces are empty. Is that the WIP state?

{
IReadOnlyCollection<string> Aliases { get; }

IReadOnlyCollection<string> RawAliases { get; }

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.

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.

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 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

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.

What else might it be?

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.

It could be a different implementation of ICommand, though we have no intention of creating another implementation at the moment.

@jonsequitur

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test Ubuntu16.04 Release

@jonsequitur jonsequitur changed the title [WIP] Simplified, mutable parser config Simplified, mutable parser config Oct 16, 2018
@jonsequitur
jonsequitur merged commit fd3ec46 into dotnet:master Oct 16, 2018
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.

4 participants