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

feature request: dynamic defaults #4

Open
teidesu opened this issue Oct 30, 2024 · 0 comments
Open

feature request: dynamic defaults #4

teidesu opened this issue Oct 30, 2024 · 0 comments
Assignees

Comments

@teidesu
Copy link

teidesu commented Oct 30, 2024

in some cases a default value for an argument might be from an env. variable (or otherwise computed), in which case using a .default(process.env.FOO) would a) result in bad ux for the user in --help (they wouldn't know where the value comes from), and b) might be expensive

currently the workaround is to keep the argument as optional, put the default value description in the .desc() and use ?? in handler/transform function, which adds a bit of boilerplate

i propose an overload for the .default() method that would accept a function and optionally a textual description of what happens there:

const foo = command({
  name: 'foo',
  options: {
    foo: string().default(() => process.env.FOO, 'process.env.FOO'),
    bar: number().default(() => 2 ** 32),
  }
})
@Sukairo-02 Sukairo-02 self-assigned this Nov 3, 2024
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