1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const command_1 = require("@heroku-cli/command");
|
4 | const fs = require("fs-extra");
|
5 | const path = require("path");
|
6 | const completions_1 = require("./completions");
|
7 | class AutocompleteBase extends command_1.default {
|
8 | errorIfWindows() {
|
9 | if (this.config.windows) {
|
10 | throw new Error('Autocomplete is not currently supported in Windows');
|
11 | }
|
12 | }
|
13 | errorIfNotSupportedShell(shell) {
|
14 | if (!shell) {
|
15 | this.error('Missing required argument shell');
|
16 | }
|
17 | this.errorIfWindows();
|
18 | if (!['bash', 'zsh'].includes(shell)) {
|
19 | throw new Error(`${shell} is not a supported shell for autocomplete`);
|
20 | }
|
21 | }
|
22 | get autocompleteCacheDir() {
|
23 | return path.join(this.config.cacheDir, 'autocomplete');
|
24 | }
|
25 | get completionsCacheDir() {
|
26 | return path.join(this.config.cacheDir, 'autocomplete', 'completions');
|
27 | }
|
28 | get acLogfilePath() {
|
29 | return path.join(this.config.cacheDir, 'autocomplete.log');
|
30 | }
|
31 | writeLogFile(msg) {
|
32 | const now = new Date();
|
33 | let entry = `[${now}] ${msg}\n`;
|
34 | let fd = fs.openSync(this.acLogfilePath, 'a');
|
35 |
|
36 | fs.write(fd, entry);
|
37 | }
|
38 | findCompletion(cmdId, name, description = '') {
|
39 | return new completions_1.CompletionLookup(cmdId, name, description).run();
|
40 | }
|
41 | }
|
42 | exports.AutocompleteBase = AutocompleteBase;
|