Skip to content

Align parser configuration APIs to the ParseResult API surface #251

Closed

Description

@jonsequitur

A common friction point has been the differences between the fluent builder API and the Option, Command, and Argument types that are created by it when Build is called, which can then be accessed from a ParseResult.

In order to make the API more consistent and easier to understand, we should try to achieve the following:

  • Parser component types (Option, Command, Argument) should be mutable at configuration time and allow developers to set properties, add options to a command, and so on, rather than passing complex structures into constructors as is now required.
  • These types should be effectively immutable once composed into a Parser in order to keep concurrent use cases robust.
  • The configuration-time (read/write) API surface should be a superset of the parse-time (read-only) API surface, at least in terms of naming and structure, even if the underlying types are different.

Activity

  1. jonsequitur commented on Oct 12, 2018

    @jonsequitur
    ContributorAuthor

    @wli3 Re: #252 (comment)

    Good points. This issue will likely stick around longer than any one PR so it's worth moving the discussion here.

    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

    "Symbol" is being used in this sense: https://en.wikipedia.org/wiki/Symbol_(programming). We're using it to refer to the configurable elements of a developer's command line app's syntax, i.e. IOption and ICommand are ISymbols. Of course, we could maybe find clearer terminology for all of these. Any ideas?

    (Also, as part of this, I hope we can also simplify the interface definitions.)

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

    It doesn't include itself. Maybe Children would be clearer?

    _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

    The current proposal is that adding a child symbol will set the parent for you, although it's not ideal. The problem with that is that the following code would compile but the expectation is unclear:

    var command1 = new Command();
    var command2 = new Command();
    var option = new Option();
    command1.AddOption(option);
    command2.AddOption(option); // Would this reparent? Remove it from the command1? Throw?
  2. wli3 commented on Oct 12, 2018

    @wli3

    It doesn't include itself. Maybe Children would be clearer?

    That would be better. And no setter on mutable object's parent? So the user will know they should only config children

    The current proposal is that adding a child symbol will set the parent for you, although it's not ideal. The problem with that is that the following code would compile but the expectation is unclear:

    As before, make parent readonly on mutable object should help. Or AddOption method as the example, so there is only one way to do it.

    For the example below, maybe consider command1 and command2 has the same option? dotnet run and dotnet build both support --configuration option?

  3. self-assigned this
    on Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions