Skip to content

Symbols: Validators and Completions #1972

@adamsitnik

Description

@adamsitnik

Based on various recent discussions with @jozkee and @KalleOlaviNiemitalo

#1953 (comment)
https://github.com/dotnet/command-line-api/pull/1959/files#r1025309941

I've realized that:

  • we currently don't expose a possibility to remove Completions from Option<T> (Argument exposes .Completions property, but Option does not). Most of the methods exposed by Option simply delegate to .Argument which is an internal property.
  • there is more than one way of adding new completions and validators: symbol.AddValidator and symbol.Validators.Add

The questions I have:

  • should we simplify the public API surface by just exposing the mutable collections and removing Add* methods? @bartonjs what is the recommended approach for such scenarios? The change I am talking about:
public class Argument<T>
{
    public ICollection<Func<CompletionContext, IEnumerable<CompletionItem>>> Completions { get; }
-   public Argument<T> AddCompletions(Func<CompletionContext, IEnumerable<CompletionItem>> completionsDelegate)
// we don't expose ClearCompletions()
}
  • should we remove the Option methods that just delegate to Argument and expose Option.Argument? @jonsequitur this has most likely been discussed in the past, what is the main reason for not exposing this property?
public class Option<T>
{
+   public Argument<T> { get; }
-    public void SetDefaultValue(T value);
-    public void SetDefaultValueFactory(Func<T> defaultValueFactory)
-    public Option<T> AcceptOnlyFromAmong(params string[] values)
-    public Option<T> AddCompletions(params string[] completions)
-    public Option<T> AddCompletions(Func<CompletionContext, IEnumerable<string>> completionsDelegate)
-    public Option<T> AddCompletions(Func<CompletionContext, IEnumerable<CompletionItem>> completionsDelegate)
-    public Option<T> AcceptLegalFilePathsOnly()
-    public Option<T> AcceptLegalFileNamesOnly()
}

It would simplify the public API surface and we would avoid the issues where not every method exposed by Argument is exposed by Option, but at a cost of losing the fluent API builder capabilities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions