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 have a draft PR to address this, but I feel like I probably did it wrong. What I'd like is to be able to assign a default value to a pref in such a way that it's not actually evaluated until Args.fill is called--the main use case is to prevent mallsearches in garbo before we do our big mallPrices("allitems") but I'm sure there are other use cases
The text was updated successfully, but these errors were encountered:
Hmm, interesting idea. Some things I'll have to think about:
Typing
Right now the presence of default changes the type of the generated argument:
a: Args.number({}) generates a field args.a: number | undefined, which is undefined before args are parsed or if a is not provided.
a: Args.number({default: 2}) generates a field args.a: number, which is 2 before args are parsed or if a is not provided in the command.
Probably an argument with a delayed default would have to allow undefined, and be initialized to undefined before the args are filled.
Help
The help text currently displays the default value if given. I guess delayed defaults should show nothing in the help? Or maybe it is better to compute it and show the computed value.
--
As a workaround, I will also note that the args object is an entirely normal and mutable object (just with some hidden fields). So it should work fine to do something like:
Args.fill(args, command);
if (!args.target) args.target = defaultTarget();
I suppose this is modifying a global, and defined further away from the other arg definitions, so not ideal.
I have a draft PR to address this, but I feel like I probably did it wrong. What I'd like is to be able to assign a default value to a pref in such a way that it's not actually evaluated until
Args.fill
is called--the main use case is to prevent mallsearches in garbo before we do our bigmallPrices("allitems")
but I'm sure there are other use casesThe text was updated successfully, but these errors were encountered: