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
I initially constructed my options using a pattern like this:
var population = new Option<int>(
new[] { "-p", "--population" },
getDefaultValue: () => 1000,
description : "Number of people to simulate" );
But I found default values weren't showing up after parsing the command line, so I switched the pattern to this:
var population = new Option<int>(
new[] { "-p", "--population" },
description : "Number of people to simulate" )
{
Argument = new Argument<int>(()=>1000)
};
This works find. But I don't understand what's wrong with the original pattern. What am I missing?
BTW, this is a >>fantastic<< package! Good luck in continuing to hone it!
That's the same release I'm using (just wrote the code yesterday). Offhand the one difference I see between your test code and what I originally did was that I set Argument within the Option initializer, even before I included the default value Func within the Argument constructor. Could that have made a difference? Is is it necessary to set Argument or does it get created by default by the Option constructor?
I confirmed that moving the default value setter into the Option constructor and eliminating setting Argument in the initializer resolves the issue I cited.
Apropos of whether or not to hide or remove the Argument property, is there another way of setting a validator on an Option? I'm using a pattern like this:
var population = new Option<int>(
new[] { "-p", "--population" },
getDefaultValue : () => 1000,
description : "Number of people to simulate" );
population.Argument.AddValidator(
x => x.GetValueOrDefault<int>() < 100 ? "Population must be >= 100" : null );
Activity
jonsequitur commentedon Apr 1, 2020
Your first sample works for me when using 2.0.0-beta1.20158.1. Can you check the version you're using?
markolbert commentedon Apr 1, 2020
That's the same release I'm using (just wrote the code yesterday). Offhand the one difference I see between your test code and what I originally did was that I set Argument within the Option initializer, even before I included the default value Func within the Argument constructor. Could that have made a difference? Is is it necessary to set Argument or does it get created by default by the Option constructor?
jonsequitur commentedon Apr 1, 2020
Ah! The
Option<T>constructor delegates to the Argument property, so you might have overwritten thegetDefaultValuefrom the constructor.The
Option.Argumentproperty is a bit confusing in this way and we've considered removing or hiding it.@KathleenDollard Any thoughts on this?
markolbert commentedon Apr 1, 2020
I confirmed that moving the default value setter into the Option constructor and eliminating setting Argument in the initializer resolves the issue I cited.
Apropos of whether or not to hide or remove the Argument property, is there another way of setting a validator on an Option? I'm using a pattern like this:
jonsequitur commentedon Apr 3, 2020
There isn't currently but we would need to address that in order to hide the
Option.Argumentproperty.Another proposed change for validators is to have them operate on bound values rather than tokens, so you could just write something like this:
markolbert commentedon Apr 3, 2020
That would be a nice enhancement, too. Again, a wonderful library!
Shall I close this thread?