1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AutocompleteBase = void 0;
|
4 | const core_1 = require("@oclif/core");
|
5 | const fs = require("fs-extra");
|
6 | const path = require("path");
|
7 | class AutocompleteBase extends core_1.Command {
|
8 | get cliBin() {
|
9 | return this.config.bin;
|
10 | }
|
11 | get cliBinEnvVar() {
|
12 | return this.config.bin.toUpperCase().replace('-', '_');
|
13 | }
|
14 | determineShell(shell) {
|
15 | if (!shell) {
|
16 | this.error('Missing required argument shell');
|
17 | }
|
18 | else if (this.isBashOnWindows(shell)) {
|
19 | return 'bash';
|
20 | }
|
21 | else {
|
22 | return shell;
|
23 | }
|
24 | }
|
25 | errorIfWindows() {
|
26 | if (this.config.windows && !this.isBashOnWindows(this.config.shell)) {
|
27 | throw new Error('Autocomplete is not currently supported in Windows');
|
28 | }
|
29 | }
|
30 | errorIfNotSupportedShell(shell) {
|
31 | if (!shell) {
|
32 | this.error('Missing required argument shell');
|
33 | }
|
34 | this.errorIfWindows();
|
35 | if (!['bash', 'zsh'].includes(shell)) {
|
36 | throw new Error(`${shell} is not a supported shell for autocomplete`);
|
37 | }
|
38 | }
|
39 | get autocompleteCacheDir() {
|
40 | return path.join(this.config.cacheDir, 'autocomplete');
|
41 | }
|
42 | get acLogfilePath() {
|
43 | return path.join(this.config.cacheDir, 'autocomplete.log');
|
44 | }
|
45 | writeLogFile(msg) {
|
46 | const entry = `[${(new Date()).toISOString()}] ${msg}\n`;
|
47 | const fd = fs.openSync(this.acLogfilePath, 'a');
|
48 | fs.write(fd, entry);
|
49 | }
|
50 | isBashOnWindows(shell) {
|
51 | return shell.endsWith('\\bash.exe');
|
52 | }
|
53 | }
|
54 | exports.AutocompleteBase = AutocompleteBase;
|