Repository navigation
Closed
Description
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
CompletionsfromOption<T>(Argument exposes.Completionsproperty, but Option does not). Most of the methods exposed by Option simply delegate to.Argumentwhich is an internal property. - there is more than one way of adding new completions and validators:
symbol.AddValidatorandsymbol.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
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 Argument is exposed by Option, but at a cost of losing the fluent API builder capabilities.
Reacted by David Cantú
Metadata
Metadata
Assignees
Labels
No labels
Activity
adamsitnik commentedon Nov 17, 2022
A different solution we have discussed offline was to make
Option<T>derive fromArgument<T>. I am going to write a simple prototype and verify how good/bad this idea is.KalleOlaviNiemitalo commentedon Nov 20, 2022
@adamsitnik would that change affect the tokens in OptionResult and ArgumentResult?
adamsitnik commentedon Nov 22, 2022
I've given it a try and it's not worth it.
Advantages:
Option<T>Disadvantages:
Argumentdoes not derive fromIdentifierSymbol, butOptionandCommanddo. Since we have no multiple class inheritance, theIdentifierSymbolAPIs would need to be duplicated forOption<T>andCommand.Optiontype that is required to store options of different kinds that belong to a singleCommandinstance. This could be worked around by having anOptioninterface, but it would also need to be public so it would defeat our purpose (fewer public types and APIs). Moreover,Optioninterface would never derive fromSymboltype, so we would need to castOptiontoSymbolin multiple places.Option<T>methods would always return anArgument<T>, which would make it hard to use as an option laterWe could achieve multiple class inheritance by changing
OptionandIdentifierSymbolto interfaces with default implementations, but this would not work with older .NET Runtimes.The lists are not complete as I did not want to invest too much time working on it.