UNPKG

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