1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const cli_framework_1 = require("@ionic/cli-framework");
|
4 | const utils_terminal_1 = require("@ionic/utils-terminal");
|
5 | const path = require("path");
|
6 | const color_1 = require("../lib/color");
|
7 | const command_1 = require("../lib/command");
|
8 | const errors_1 = require("../lib/errors");
|
9 | class 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: `
|
16 | This command is experimental and only works for Z shell (zsh) and non-Windows platforms.
|
17 |
|
18 | To 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" ],
|
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 | }
|
46 | exports.CompletionCommand = CompletionCommand;
|