UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@heroku-cli/command");
4const fs = require("fs-extra");
5const path = require("path");
6const completions_1 = require("./completions");
7class 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 const entry = `[${now}] ${msg}\n`;
34 const fd = fs.openSync(this.acLogfilePath, 'a');
35 // eslint-disable-next-line
36 // @ts-ignore
37 fs.write(fd, entry);
38 }
39 findCompletion(cmdId, name, description = '') {
40 return new completions_1.CompletionLookup(cmdId, name, description).run();
41 }
42}
43exports.AutocompleteBase = AutocompleteBase;