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

bug: custom completion with promise does trigger validation #1235

Closed
buehler opened this issue Oct 26, 2018 · 2 comments
Closed

bug: custom completion with promise does trigger validation #1235

buehler opened this issue Oct 26, 2018 · 2 comments

Comments

@buehler
Copy link

buehler commented Oct 26, 2018

Hey there, I'm currently experiencing the following bug:

When using completions, a synchronuous handler does not trigger the validation (which is correct),
but when I have a command foobar <arg> and try to use the completion node . --get-yargs-completions foobar with a custom completion handler that returns a promise

.completion('completion', false as any, (_, argv: Arguments) => {
        return Promise.resolve(['asdf']);
      }),

It does trigger the validation of the required argument and therefor executes the completion handler, but then the process gets exited with the error that a required argument is missing.

Also, when using promises, the handler of the command is executed as well.

@buehler
Copy link
Author

buehler commented Oct 31, 2018

As I investigated, the same happens when using async.

@bcoe
Copy link
Member

bcoe commented Jan 4, 2021

@buehler not 100% sure when I fixed this, but it seems to be fixed in #1823

import yargs from 'yargs';
import { setTimeout } from 'timers/promises';

yargs(process.argv.slice(2))
  .command('foobar <arg>', 'the foobar command', (yargs) => {
    yargs.command('blerg', 'blerg command');
  })
  .completion('completion', false, async (_, argv) => {
    await setTimeout(1000)
    return Promise.resolve(['hello', 'world'])
  })
  .parse();

☝️ outputs:

hello
world

With no error.

@bcoe bcoe closed this as completed Jan 4, 2021
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