You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this gist, two verbs are introduced both with a required positional argument. Both Values have a MetaName. The meta name is used in the description during the help text, but not in the error message.
Actual behavior
$ calc fib --help
calc 1.0.0
Copyright (C) 2021 calc
--help Display this help screen.
--version Display version information.
position of the fibonacci number to calculate (pos. 0) Required.
This is ok and expected. But omitting the --help leads to the following error:
$ calc fib
calc 1.0.0
Copyright (C) 2021 calc
ERROR(S):
A required value not bound to option name is missing.
--help Display this help screen.
--version Display version information.
position of the fibonacci number to calculate (pos. 0) Required.
Expected behavior
$ calc fib
calc 1.0.0
Copyright (C) 2021 calc
ERROR(S):
The required position of the fibonacci number to calculate (value at position 0) is missing.
--help Display this help screen.
--version Display version information.
position of the fibonacci number to calculate (pos. 0) Required.
Possible error sources analyzed
In SpecificationPropertyRules, a MissingRequiredOptionError error is issued for the ValueSpecification using the NameExtensions FromSpecification method. For a ValueSpecification, the resulting NameInfo object is set to an empty instance. This might be intentional, but will cause the error here.
Suggested fixes
Extend NameExtensions class as follows:
public static NameInfo FromValueSpecification(this ValueSpecification specification)
{
return !string.IsNullOrWhitespace(specification.MetaName)
? new NameInfo(
string.Empty,
specification.MetaName)
: NameInfo.EmptyName ;
}
public static NameInfo FromSpecification(this Specification specification)
{
switch (specification.Tag)
{
case SpecificationType.Option:
return FromOptionSpecification((OptionSpecification)specification);
case SpecificationType.Value:
return FromValueSpecification((ValueSpecification)specification);
default:
return NameInfo.EmptyName;
}
}
This clarifies the error message more to
ERROR(S):
Required option 'position of the fibonacci number to calculate' is missing.
If this is not yet appropriate enough, we can update SpecificationPropertyRules in addition to 1 like follows:
from sp in missing
select
sp.IsOption() ? new MissingRequiredOptionError(sp.FromSpecification()) as Error
: new MissingValueOptionError(sp.FromSpecification()) as Error;
This changes the error to
Option 'position of the fibonacci number to calculate' has no value.
which might not be good.
Take approach (2) but introduce a new MissingRequiredPositionalValueError including the extension of Errors, SentenceBuilder, etc.
If you accept the issue, I can submit a PullRequest for each of the three issues, if you tell me, which way to go.
If you do not accept the issue, please tell me a feasible workaround or tell me the reason, why this should be considered as intentional.
Cheers
Carsten
The text was updated successfully, but these errors were encountered:
Me too - somewhere I found that in theory using preview 3 with GetOptMode = true would fix it, but the lack of availabilty on nuget.org had me struggling.
Synopsis
If a required value with a
MetaName
is omitted, the error is depicted as Option, which might be misleading:Version used
2.8.0
System Description
Gist for reproduction
Example Repository
In this gist, two verbs are introduced both with a required positional argument. Both Values have a MetaName. The meta name is used in the description during the help text, but not in the error message.
Actual behavior
This is ok and expected. But omitting the
--help
leads to the following error:Expected behavior
Possible error sources analyzed
In SpecificationPropertyRules, a
MissingRequiredOptionError
error is issued for the ValueSpecification using the NameExtensionsFromSpecification
method. For a ValueSpecification, the resultingNameInfo
object is set to an empty instance. This might be intentional, but will cause the error here.Suggested fixes
NameExtensions
class as follows:This clarifies the error message more to
This changes the error to
which might not be good.
MissingRequiredPositionalValueError
including the extension of Errors, SentenceBuilder, etc.If you accept the issue, I can submit a PullRequest for each of the three issues, if you tell me, which way to go.
If you do not accept the issue, please tell me a feasible workaround or tell me the reason, why this should be considered as intentional.
Cheers
Carsten
The text was updated successfully, but these errors were encountered: