Skip to content

Commit

Permalink
docs: add completion filter docs (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobator committed Mar 2, 2021
1 parent 01619f6 commit b368f95
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/api.md
Expand Up @@ -397,6 +397,27 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
.argv;
```

Using default completions in a custom implementation. When invoked with no arguments, `completionFilter` will fallback to the default completion function. There is no need to call `done` in this case. When provided with a callback function, you can get access to `defaultCompletions` and call `done` with your processed version of them.

```js
var argv = require('yargs/yargs')(process.argv.slice(2))
.completion('completion', function(current, argv, completionFilter, done) {
// if 'apple' present return default completions
if (argv._.includes('apple')) {
completionFilter();
} else {
completionFilter((err, defaultCompletions) => {
const filteredCompletions = defaultCompletions.filter(
completion => !completion.includes('banana'),
);
// else return default completions w/o 'banana'
done(filteredCompletions);
});
}
})
.argv;
```

<a name="config"></a>.config([key], [description], [parseFn])
-------------------------------------------------------------
.config(object)
Expand Down

0 comments on commit b368f95

Please sign in to comment.