-
Notifications
You must be signed in to change notification settings - Fork 401
make Symbol.Name mandatory, non-nullable and readonly #2067
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
Conversation
…nt and Option: * both always have Name specified, so first column can't contain enum values for Arguments with no name anymore * move enum values to second column, but only for symbols with no description
@@ -42,7 +42,7 @@ public void FindResult_can_be_used_to_check_the_presence_of_an_option() | |||
[Fact] | |||
public void FindResultFor_can_be_used_to_check_the_presence_of_an_implicit_option() | |||
{ | |||
var option = new Option<int>(new[] { "-c", "--count" }, () => 5); | |||
var option = new Option<int>("--count", new[] { "-c", "--count" }, () => 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var option = new Option<int>("--count", new[] { "-c", "--count" }, () => 5); | |
var option = new Option<int>("count", new[] { "-c", "--count" }, () => 5); |
{ | ||
var option = new Option<string>(new[] { "myname", "m" }); | ||
var option = new Option<string>("--myname", new[] { "myname", "m" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var option = new Option<string>("--myname", new[] { "myname", "m" }); | |
var option = new Option<string>("myname", new[] { "myname", "m" }); |
@@ -70,39 +60,39 @@ public void A_prefixed_alias_can_be_added_to_an_option() | |||
[Fact] | |||
public void Option_aliases_are_case_sensitive() | |||
{ | |||
var option = new Option<string>(new[] { "-o" }); | |||
var option = new Option<string>("-o", new[] { "-o" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var option = new Option<string>("-o", new[] { "-o" }); | |
var option = new Option<string>("o", new[] { "-o" }); |
@@ -141,7 +131,7 @@ public void An_option_cannot_have_an_alias_consisting_entirely_of_whitespace() | |||
[Fact] | |||
public void Raw_aliases_are_exposed_by_an_option() | |||
{ | |||
var option = new Option<string>(new[] { "-h", "--help", "/?" }); | |||
var option = new Option<string>("--help", new[] { "-h", "--help", "/?" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var option = new Option<string>("--help", new[] { "-h", "--help", "/?" }); | |
var option = new Option<string>("help", new[] { "-h", "--help", "/?" }); |
} | ||
|
||
AddAlias(name); | ||
AddAlias(name ?? throw new ArgumentNullException(nameof(name))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this matches the prior behavior, but are we sure we want to keep this? This looks like it will potentially cause un-expected behavior where the name is only sometimes added to the list of aliases.
{ | ||
if (string.IsNullOrWhiteSpace(name)) | ||
{ | ||
throw new ArgumentException("A name cannot be null, empty, or consist entirely of whitespace."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new ArgumentException("A name cannot be null, empty, or consist entirely of whitespace."); | |
throw new ArgumentException("A name cannot be null, empty, or consist entirely of whitespace.", nameof(name)); |
{ | ||
var rootCommand = new RootCommand(); | ||
rootCommand.Name = "custom"; | ||
rootCommand.AddAlias("custom"); | ||
|
||
rootCommand.Aliases.Should().BeEquivalentTo("custom", RootCommand.ExecutableName); | ||
rootCommand.Aliases.Should().BeEquivalentTo("custom", RootCommand.ExecutableName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize these lines were not changed, but do we need both of these assertions? They appear to be duplicates.
I'm hesitant on this change.
|
So far to get
You mean lack of compiler errors because all the ctors accept just strings? I've a proposal for how we could simplify that: #2053 (comment)
I am not sure if I understand. What do you mean by grammar? The parsing rules? Argument is a parameter with no name, so it was not used for parsing. Options name was not the actual alias, but a shortened version of it. So it was also not used for parsing. Could you please elaborate more on that?
I can add lookups by alias, especially since some products like SDK provide localized names for their symbols. |
|
Yes. I looked at the comment you mentioned and it includes a sample like this: new Option<bool>("ucr", "--ucr", "--use-current-runtime") I think the repetition of Another approach might be to require a Arguments don't need the alias concept and the name can be used for indexing pretty intuitively as is. |
This sounds like a new scenario that deserves some discussion. Localizing actual identifiers sounds like a pretty uncommon case, and needing to know the localized identifier to perform a lookup sounds like it would invite a lot of bugs for API users. |
Closing in favor of #2073 |
The goal of this PR it to make
Name
a mandatory, readonly and non empty value for everySymbol
.We need that to implement #2052:
ParseResult.GetValue<T>(string name)
, which is going to allow our users to use the symbol name to fetch parsed value without the need of storing reference to Symbol.Before:
After
Another motivation is to remove
Option.ArgumentHelpName
which is confusing, as the fact thatOption
wraps anArgument
is an implementation detail.Last but not least,
Argument
being a parameter without a name, but having bothName
andHelpName
property was also confusing.This required changes in help. So far, the value of first column was
Argument.HelpName
if present, completions (if any) orArgument.Name
otherwise.command-line-api/src/System.CommandLine/Help/HelpBuilder.Default.cs
Lines 73 to 86 in 1e15ab1
Not everybody like that: #1976 and some of our users were setting
Argument.HelpName
just to avoid having all completions displayed in help.Now the first column contains the Name (because it is always present), while second chooses Description. If description is not provided, it's using the completions.
fixes #1895
fixes #2038
fixes #2051
unblocks #2052 (required data will be always present)
unblocks #2053 (avoids conflicts related to ctors changes)