Skip to content

Dynamic completions #2390

Open
Open
@daguej

Description

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions