Repository navigation
Closed
Description
Based on the feedback from @bartonjs :
- Rename
Argument,Option, andCommandto disambiguate from other single-word types #1892 - Consider a more commonly-known word than "arity" #1893
- Rename
getDefaultValueparameter todefaultValueFactory#1894 - Does an argument with no name make sense? #1895
- Move extension methods into the extended type #1896
- Rename
ExistingOnly#1897 - Rename parameters to align on the word "completion" #1898
- Rename
FromAmongto include a verb #1899 - Rename
LegalFileNamesOnlyto include a verb #1900 - Move
Parseextension methods to the appropriateSymboltypes #1901 - Rename
TreatUnmatchedTokensAsErrorsso that it'sfalseby default and clearer in intent #1902 - Consider removing
Command.AddOption,Command.AddCommand, andCommand.AddArgumentbecause they're redundant withAdd#1903 - Consider a better word than "global" since it actually indicates that the option is syntactically valid on the current command and its subcommands #1904
- Move
Invoke*andParseextension methods to their extendedSymboltypes #1905 - Align naming of
CommandLineConfigurationto renamedSymboltypes, e.g.CliConfiguration#1906 - Redesign
CommandLineConfigurationto be mutable and favor properties over constructors #1907 - Consider renaming
ThrowIfInvalidto clarify the intent #1908 - Remove
CommandLineConfigurationException#1909 - Move
CompletionSourceListextension methods toCompletionSourceList#1910 - Consider removing
CompletionSourceList#1911 - Consider removing
DirectiveCollection#1912 - Move SetHandler to another package for backcompat #1913
- API summarizer for ApprovalTests does show
overridemethods correctly. #1914 - Consider a new localization design #1915
- Consider renaming
Symbolto be less likely to collide and to be consistent with the renaming of its derived types. #1916 - Consider renaming and/or moving types out of the
Bindingnamespace. #1917 - Consider the binding space, including whether
BinderBase<T>,IValueSource, andIValueDescriptorare needed in the public API for usage beyondSetHandler#1918 - Consider whether service resolution needs to be in the public API #1919
- Move
CommandLineBuilderinto the application framework layer #1920 - Consider adding a general capability, independent of current invocation concepts, to align shutdown handling with standard cancellation APIs. (For example, should
CancellationTokensupport be available inasync Main?) #1921 - Move appropriate
CommandLineBuildermethods to properties onCommandLineConfiguration#1922 - Move
RegisterWithDotnetSuggestto the application framework layer and consider making it internal, as it will ideally be replaced eventually by intrinsic SDK or runtime support #1923 - Consider whether
UseDefaultsis still needed #1924 - Consider moving
UseVersionOptiontoCommandLineConfigurationand renaming #1925 - Consider moving
UseTokenReplacertoCommandLineConfigurationand renaming #1926 - Replace
CompletionDelegatewithAction<CompletionContext>#1927 - Consider whether
ICompletionSourcecan be replaced with a delegate or class #1928 - Consider differentiating these two
*CompletionContextscenarios using fewer public types #1929 - Move
HelpBuilderinto a separate package #1930 - Consider an alternative that doesn't have
HelpBuilder.Defaultas a nested class #1931 - Remove
HelpSectionDelegateand replace withAction<HelpContext>#1932 - Consider an alternative to implementing structural equality for
TwoColumnHelpRow#1933 - Consider a
CliActiondesign that doesn't require custom implementations to override bothInvokeandInvokeAsyncmethods #1934 - Rename
ArgumentResult.OnlyTakeso that the intent is clearer #1935 - Consider using
Action<InvocationContext>and removingIInvocationResult#1936 - Consider renaming
CommandLineStringSplitter#1937 - Document all the work done by
CommandLineStringSplitterincluding its importance in testing #1938 - Replace
ParseArgument<T>withFunc<ArgumentResult, T>#1939 - Ensure directives are sufficiently documented #1940
- API summarizer for ApprovalTests shows
refforoutparameters. #1942 - API summarizer for ApprovalTests does not capture generic constraints #1943
- Replace
ValidateSymbolResultdelegate withAction<T>#1944 - Consider a different return type for
Symbol.Aliases#1945
Based on other feedback:
Reacted by Adam Goodwin
Activity
adamsitnik commentedon Nov 8, 2022
I've noted some additional questions today:
Completions
CompletionItem
KeywordandValuekinds? It seems thatKindcould be made iternal asKeywordis used only in once place andKindis used only byEqualsandGetHashCode.SortTextas a string makes it actually simpler to sort completions? Why not an int or enum? Is it actually used?Equals, but does not implementIEqutable.IComparable.Documentationdescribes the item. Symbol definesDescription. Should we unify them?Detailis needed? I would expectDocumentationto be sufficient?InsertTextworks? Is it ever different thanLabel?CompletionContext
WordToCompleteis very self-describing name, on the other it's part ofCompletionContextso I wonder whether we could simplify it:CompletionContext.Word?TokenCompletionContext
ctor. Does it need to be public? Consider differentiating these two*CompletionContextscenarios using fewer public types #1929TextCompletionContext
TokenCompletionContextit has no publicctorand seems like it could be madeinternal. Consider differentiating these two*CompletionContextscenarios using fewer public types #1929ICompletionSource
ICompletionSourcebut don't derive fromSymbol? Consider whetherICompletionSourcecan be replaced with a delegate or class #1928Edit: I can see there are
AnonymousCompletionSourcefor representing plain strings andCompletionSourceForTypewhich more or less delegates toAnonymousCompletionSource. So in theory we could removeICompletionSourcenad introduce an artifical symbol for representing a simple completions source.Symbols
Symbol
Parenthierarchy is used by customers outside ofS.CL? Can it be madeinternal?GetCompletions(void)is part ofSymbol, butGetCompletions(CompletionContext)is part ofICompletionSourceiterface. Do we need both? We could makecontextan optional argument or just removeGetCompletions(void)as it seems to be used only for internal purposes.Argument
Completionsis a collection ofICompletionSource, while all the usages in test project more or less provide a single source with multiple completion items. Should it be a collection ofCompletionIteminstead?In most of the
Completionsusages in test project the property is initialized only once, when the model is being created. Would it make sense to expose the possibility to add new completions only at creation time viactor? And why do we needClear? This could allow us for makingCompletionsprivate and an implementation detail and get closer to having symbols immutable?The completions are sorted and verified for duplication every time
GetCompletionsis called. How frequently is this method being called? Should we do it only once?KalleOlaviNiemitalo commentedon Nov 8, 2022
For a hidden Option<bool>: I had a command-line application with an
--out-clipboardoption that used System.Windows.Forms.Clipboard. Then I was porting it to net6.0 (not net6.0-windows) where Windows Forms is not available and the option cannot work. I setIsHidden = trueto hide the unusable option from help and completions. I could have put#ifaround the whole option, but I chose to keep it in the parser for a few reasons:KalleOlaviNiemitalo commentedon Nov 8, 2022
Related #1765.
Related #1220 (comment).
IIUC, a completion menu (perhaps a popup in PowerShell) could display Label and then insert InsertText. But the suggest directive currently uses Label only, so dotnet-suggest will complete incorrectly if the completion delegate sets different strings in them.
Help likewise uses Label only; I think that too should be InsertText. Even though the help is displayed to the user and Label therefore seems correct, it is intended for the user to copy to a command so InsertText is better.
command-line-api/src/System.CommandLine/Help/HelpBuilder.Default.cs
Line 70 in 8b66431
KalleOlaviNiemitalo commentedon Nov 8, 2022
I feel this would suggest it is already a complete word, rather than part of a word.
KalleOlaviNiemitalo commentedon Nov 8, 2022
I need it in #1884.
KalleOlaviNiemitalo commentedon Nov 8, 2022
AFAIK, GetCompletions is not normally called more than once for the same Symbol in the same process. It might be called again in an interactive application that reads more commands, but then it would likely have a new CompletionContext so you wouldn't be able to cache anyway.
KalleOlaviNiemitalo commentedon Nov 8, 2022
I use Symbol.GetCompletions() for testing a custom completion callback; please do not remove this feature. The alternative Symbol.GetCompletions(CompletionContext) is not suitable because AFAICT there is no way for external code to create a ComplationContext instance; it and the two derived classes all have internal constructors.
KalleOlaviNiemitalo commentedon Nov 8, 2022
No, the completion items can depend on the parse results of other symbols. Like an Argument<FileInfo> specifies a file and an Option<string> specifies an identifier defined in that file, and the completion delegate reads the file to find out what identifiers are defined there and what completion items should be generated. Also, I believe System.CommandLine currently requires the app to set up the arguments and options of all subcommands in advance (#1956), and if you require it to generate all the completion items in advance too, that will cost time during startup.
I think a property
public Func<CompletionContext, IEnumerable<CompletionItem>> Completer { get; set; }would be OK, though. Multiple completion sources don't seem very common, and an app developer who wants multiple can set up a wrapper that calls them in the desired order.adamsitnik commentedon Nov 8, 2022
@KalleOlaviNiemitalo big thanks for all the answers!
PTAL at #1954 and let me know what do you think.
KalleOlaviNiemitalo commentedon Nov 8, 2022
Why CompletionItem.Label would ever differ from InsertText:
Localization. InsertText could be culture-invariant so that a shell script works in all cultures, while Label would be localised.
Quoting. Maybe Label is
@opbut InsertText is@@opto quote it for the response file feature. OTOH, I don't think this kind of quoting should be done by the completion delegates; they should be agnostic of parser configuration. Likewise, they should not quote$varas\$varbecause it's not their business to know what kind of shell the user is using.adamsitnik commentedon Nov 10, 2022
Do we really need 3 different ways of specyfing default value? (
object value,action<object>,Func<ParseResult,object>)? How about just two?Argument is an arugment without name, but:
In what scenario the customer needs both Name and HelpName for Argument?
and it's used by two extension methods:
FromAmong. Could it be removed and implemented using a validator? (it's impl detail as it's currently not exposed publicly)Argument
It has six public ctors, some of them define optional arguments, some do not. How about introducing just one with multiple optional arguments?
I find it confusing to use a boolean flag to tell the argument to use its custom parser as default value factory.
I would expect that any custom parser can just return default value if they want to?
ArgumentArity
IdentifierSymbol
If we want to allow for hidden aliases, we should introduce the concept of
Aliasnow. Any objections?Perf: it always allocates a HashSet. We need to find a way to avoid doing that (I have tried once and failed but it's doable).
Nameis mutable. Why? IMO we should make it readonly and initialized only byctor.Option
Argument defines
HelpName, whileOption:ArgumentHelpName. Why not justHelpName?Similarly to
Argument, why non-genericOptionallows for settingobjectdefautl value or factory?Does
HasAliasIgnoringPrefixreally needs to be public? Why would any customer outside of S.CL use it?Option
Same as for
Argumen<T>: why so many ctors? And the confusingbool isDefault?Arity seems to be redundant as it does exactly the same thing as the base type implementation?
Command
AddvsAddX. Which one do we keep?Why does it need to implement
IEnumerable<Symbol>and exposeIEnumerable<Symbol> Childrenat the same time? Is it because the duck typing for C# syntax?RootCommand
RootCommand?KalleOlaviNiemitalo commentedon Nov 12, 2022
Argument.Name is culture-invariant and can be compared to names from reflection, while Argument.HelpName is localized and displayed in help.
command-line-api/src/System.CommandLine.NamingConventionBinder/CommandResultExtensions.cs
Line 21 in e2cdee3
command-line-api/src/System.CommandLine.NamingConventionBinder/ParameterDescriptor.cs
Line 26 in e2cdee3
command-line-api/src/System.CommandLine.NamingConventionBinder/PropertyDescriptor.cs
Line 23 in e2cdee3
command-line-api/src/System.CommandLine/Help/HelpBuilder.Default.cs
Lines 74 to 87 in e2cdee3
tmds commentedon Mar 22, 2023
Besides the properties, another difference is
Commandexpects the commands to be named, andRootCommanddoes not require a name on construction. I assume that is the reason the type exists.Independent of whether the type stays or goes, it would be nice that APIs accept a
Commandinstead of aRootCommand. I have a derivedCommandtype, and currently I can't pass it to APIs that explicitly require aRootCommand.Any additional properties (if ever needed) can be added to
CommandLineConfigurationinstead ofRootCommand.adamsitnik commentedon Mar 22, 2023
That is definitely one of our goals.
I was just thinking about creating a parameterless
Commandctor, but it would make it easy to use it by accident. An alternative is creating a static factory method on theCommand:tmds commentedon Mar 22, 2023
Yes, and if you prefer to not have factory methods. You could keep the
RootCommandfor the sole purpose of being that factory. (That is: make itsealedand only have a constructor.)