UNPKG

2.05 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.CompletionCommand = void 0;
4const cli_framework_1 = require("@ionic/cli-framework");
5const utils_terminal_1 = require("@ionic/utils-terminal");
6const path = require("path");
7const color_1 = require("../lib/color");
8const command_1 = require("../lib/command");
9const errors_1 = require("../lib/errors");
10class CompletionCommand extends command_1.Command {
11 async getMetadata() {
12 return {
13 name: 'completion',
14 type: 'global',
15 summary: 'Enables tab-completion for Ionic CLI commands.',
16 description: `
17This command is experimental and only works for Z shell (zsh) and non-Windows platforms.
18
19To enable completions for the Ionic CLI, you can add the completion code that this command prints to your ${color_1.strong('~/.zshrc')} (or any other file loaded with your shell). See the examples.
20 `,
21 groups: ["experimental" /* EXPERIMENTAL */],
22 exampleCommands: [
23 '',
24 '>> ~/.zshrc',
25 ],
26 };
27 }
28 async run(inputs, options) {
29 if (utils_terminal_1.TERMINAL_INFO.windows) {
30 throw new errors_1.FatalException('Completion is not supported on Windows shells.');
31 }
32 if (path.basename(utils_terminal_1.TERMINAL_INFO.shell) !== 'zsh') {
33 throw new errors_1.FatalException('Completion is currently only available for Z Shell (zsh).');
34 }
35 const words = options['--'];
36 if (!words || words.length === 0) {
37 const namespace = this.namespace.root;
38 const formatter = new cli_framework_1.ZshCompletionFormatter({ namespace });
39 process.stdout.write(await formatter.format());
40 return;
41 }
42 const ns = this.namespace.root;
43 const outputWords = await cli_framework_1.getCompletionWords(ns, words.slice(1));
44 process.stdout.write(outputWords.join(' '));
45 }
46}
47exports.CompletionCommand = CompletionCommand;