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.
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:
CompletionsfromOption<T>(Argument exposes.Completionsproperty, but Option does not). Most of the methods exposed by Option simply delegate to.Argumentwhich is an internal property.symbol.AddValidatorandsymbol.Validators.AddThe questions I have:
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() }Optionmethods that just delegate toArgumentand exposeOption.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
Argumentis exposed byOption, but at a cost of losing the fluent API builder capabilities.