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

Options cannot be used during object construction #129

Open
swandir opened this issue Sep 12, 2022 · 2 comments
Open

Options cannot be used during object construction #129

swandir opened this issue Sep 12, 2022 · 2 comments

Comments

@swandir
Copy link

swandir commented Sep 12, 2022

Options appear as regular public class fields but do not function as such during class instance construction.

class DefaultCommand extends Command {
  static paths = [Command.Default];

  s = Option.String('-s', {
    required: true,
  });

  uppercase = this.s.toUpperCase(); // TypeError: this.s.toUpperCase is not a function

  async execute() {}
}

https://stackblitz.com/edit/node-gbmupy?file=cli.ts

This behavior is understandable given the way options are declared, but still might take the user by surprise. Especially when it fails silently (optional property usage, for example).

@arcanis
Copy link
Owner

arcanis commented Sep 12, 2022

Indeed; we could avoid that by making Option.String & friends return a Proxy that would "buffer" all manipulations, but it'd be quite overkill imo. I'm not sure what else we can do 🤔

@swandir
Copy link
Author

swandir commented Sep 14, 2022

Hmm, could options return the actual value and register themselves for command routing as a side-effect? It would require to delay command construction until after cli.run is called though 🤔

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