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

Lazy initial values for options #172

Open
johngeorgewright opened this issue Dec 19, 2024 · 0 comments
Open

Lazy initial values for options #172

johngeorgewright opened this issue Dec 19, 2024 · 0 comments

Comments

@johngeorgewright
Copy link

I'm in a scenario where I'd like to asynchronously provide default values only when a value isn't provided. As this isn't an option in clipanion, I am working with a fork of the project. Is this something you'd consider as part of the library?

An example:

class MyCommand extends Command {
  foo = Option.String(
    '-f,--foo',
    async () => {
      // The value wasn't provided.
      // Fetch something asynchronously?
      // Maybe prompt the user for extra information?
    }
  )
}

I understand this can be achieved by adding logic in Command.prototype.execute...

  override async execute() {
    const foo = await handleFooOption(this.foo)
    const other = await handleOtherOption(this.other)
    // ...
  }

However, the above isn't very scaleable as the project grows.

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

1 participant