Skip to content

Expose List properties, remove Add* methods #1987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 15, 2022

Conversation

adamsitnik
Copy link
Member

Based on feedback from @bartonjs

By exposing a single List<T> returning property we allow the users to not only add new items, but also remove them (#1884)

fixes #1972
fixes #1884

Comment on lines 27 to 28
public Argument<T> AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
public Argument<T> AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> completionsDelegate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
public Argument<T> AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
public Argument<T> AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> completionsDelegate)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jozkee great catch, #solved

public System.Boolean HasDefaultValue { get; }
public System.String HelpName { get; set; }
public System.Collections.Generic.List<System.Action<System.CommandLine.Parsing.ArgumentResult>> Validators { get; }
public System.Type ValueType { get; }
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between GetCompletions() and Completions is that the former is the result of evaluating the Funcs in the latter, right? Shouldn't we disambiguate? Maybe we can rename the List property to CompletionSources.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jozkee that is a very good point!

@KathleenDollard what is your opinion on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Can you search the code to ensure we do not already have something called "CompletionSources" as I vaguely remember that. We should update the List name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I've applied the rename and the PR is ready for review again. Thank you both for your feedback!

@adamsitnik adamsitnik requested a review from jozkee December 15, 2022 09:24
@adamsitnik
Copy link
Member Author

I've addressed all the feedback so I am going to merge it to make some progress with other PRs.

@adamsitnik adamsitnik merged commit 9eae53a into dotnet:main Dec 15, 2022
@adamsitnik adamsitnik deleted the collections branch December 15, 2022 12:52
@@ -22,10 +22,16 @@ public void Setup()
{
_nullConsole = new NullConsole();

Option<string> fruitOption = new("--fruit");
fruitOption.CompletionSources.Add("apple", "banana", "cherry");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming now looks wrong. The things being added here are really completion items, not completion sources.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonsequitur I've tried renaming the Add extension method to AddCompletionItems but it break the C# duck typing for collection initialization:

image

Error	CS1503	Argument 1: cannot convert from 'string' to 'System.Func<System.CommandLine.Completions.CompletionContext, System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>'	System.CommandLine.Tests (net462), System.CommandLine.Tests (net7.0)	D:\projects\command-line-api\src\System.CommandLine.Tests\CompletionTests.cs	125	Active

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.

Symbols: Validators and Completions Cannot replace default completions of Option<T> where T is enum
4 participants