2151
// want to complete the --help or --version option.
2152
if (requestCompletions) {
2154
>
2155
>
// we allow for asynchronous completions,
2156
>
// e.g., loading in a list of commands from an API.
2157
>
args = ([] as string[]).concat(args);
2158
>
const completionArgs = args.slice(
2159
>
args.indexOf(`--${this.#completion!.completionKey}`) + 1
2160
>
);
2161
>
this.#completion!.getCompletion(completionArgs, (err, completions) => {
2162
>
if (err) throw new YError(err.message);
2163
>
(completions || []).forEach(completion => {
2164
this.#logger.log(completion);
2166
>
this.exit(0);
2167
>
});
2168
>
return this[kPostProcess](
2169
>
argv,
2170
>
!populateDoubleDash,
2171
>
!!calledFromCommand,
2172
>
false // Don't run middleware when figuring out completion.
2173
>
);
2174
>
}
2175
2176
// Handle 'help' and 'version' options