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

Dynamic completions #2390

Open
daguej opened this issue Jan 31, 2024 · 1 comment
Open

Dynamic completions #2390

daguej opened this issue Jan 31, 2024 · 1 comment

Comments

@daguej
Copy link

daguej commented Jan 31, 2024

It would be nice if we could generate dynamic completions/choices on-the-fly when the user presses Tab in their shell. I would like to complete a positional argument or option value that's not from a hardcoded list, but eg loaded from a database.

For example, something like:

yargs().command('foo <title>', '…', (yargs) =>
  yargs.positional('title', {
    choices: async (str) => {
      const results = await database.findMany({ where: { title: { startsWith: str }}})
      return results //, an array of strings
    },
  }),
  async (argv) => {  }
);

Typing app foo ba Tab would invoke choices('ba'), which could return ['bar'], and ultimately the shell would complete the title argument with a value found in a database.

@shadowspawn
Copy link
Member

Possibly related: #831 (comment) #2298

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

No branches or pull requests

2 participants