Skip to content
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

Allow delayed defaults in Args #121

Open
horrible-little-slime opened this issue Sep 14, 2024 · 1 comment
Open

Allow delayed defaults in Args #121

horrible-little-slime opened this issue Sep 14, 2024 · 1 comment

Comments

@horrible-little-slime
Copy link
Contributor

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

@Kasekopf
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants