"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZshCompletionFormatter = exports.CompletionFormatter = exports.getCompletionWords = void 0; const lodash = require("lodash"); const guards_1 = require("../guards"); const colors_1 = require("./colors"); const options_1 = require("./options"); async function getCompletionWords(ns, argv) { const { obj } = await ns.locate(argv, { useAliases: false }); if (guards_1.isCommand(obj)) { const metadata = await obj.getMetadata(); const options = metadata.options ? metadata.options : []; if (options.length === 0) { return []; } const optionNames = options .map(option => options_1.formatOptionName(option, { showAliases: false, showValueSpec: false, colors: colors_1.NO_COLORS })) .filter(name => !argv.includes(name)); const aliasNames = lodash.flatten(options.map(option => option.aliases ? option.aliases : [])) .map(alias => `-${alias}`); return [...optionNames, ...aliasNames].sort(); } return [ ...(await obj.getCommands()).keysWithoutAliases(), ...(await obj.getNamespaces()).keysWithoutAliases(), ].sort(); } exports.getCompletionWords = getCompletionWords; class CompletionFormatter { constructor({ namespace }) { this.namespace = namespace; } } exports.CompletionFormatter = CompletionFormatter; class ZshCompletionFormatter extends CompletionFormatter { async format() { const { name } = await this.namespace.getMetadata(); return ` ###-begin-${name}-completion-### if type compdef &>/dev/null; then __${name}() { compadd -- $(${name} completion -- "$\{words[@]}" 2>/dev/null) } compdef __${name} ${name} fi ###-end-${name}-completion-### `; } } exports.ZshCompletionFormatter = ZshCompletionFormatter;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
colors.d.ts | File | 658 B | 0644 |
|
colors.js | File | 1.52 KB | 0644 |
|
command.d.ts | File | 4.19 KB | 0644 |
|
command.js | File | 9.7 KB | 0644 |
|
completion.d.ts | File | 1.26 KB | 0644 |
|
completion.js | File | 1.84 KB | 0644 |
|
config.d.ts | File | 994 B | 0644 |
|
config.js | File | 2.14 KB | 0644 |
|
executor.d.ts | File | 4.73 KB | 0644 |
|
executor.js | File | 5.93 KB | 0644 |
|
help.d.ts | File | 11.16 KB | 0644 |
|
help.js | File | 25.15 KB | 0644 |
|
index.d.ts | File | 218 B | 0644 |
|
index.js | File | 537 B | 0644 |
|
options.d.ts | File | 4.6 KB | 0644 |
|
options.js | File | 10.38 KB | 0644 |
|
validators.d.ts | File | 401 B | 0644 |
|
validators.js | File | 3.4 KB | 0644 |
|