1 | import { Command } from '@oclif/core';
|
2 | import { mkdirSync, openSync, writeSync } from 'node:fs';
|
3 | import * as path from 'node:path';
|
4 | export class AutocompleteBase extends Command {
|
5 | get acLogfilePath() {
|
6 | return path.join(this.config.cacheDir, 'autocomplete.log');
|
7 | }
|
8 | get autocompleteCacheDir() {
|
9 | return path.join(this.config.cacheDir, 'autocomplete');
|
10 | }
|
11 | get cliBin() {
|
12 | return this.config.bin;
|
13 | }
|
14 | get cliBinEnvVar() {
|
15 | return this.config.bin.toUpperCase().replaceAll('-', '_');
|
16 | }
|
17 | determineShell(shell) {
|
18 | if (!shell) {
|
19 | this.error('Missing required argument shell');
|
20 | }
|
21 | else if (this.isBashOnWindows(shell)) {
|
22 | return 'bash';
|
23 | }
|
24 | else {
|
25 | return shell;
|
26 | }
|
27 | }
|
28 | getSetupEnvVar(shell) {
|
29 | return `${this.cliBinEnvVar}_AC_${shell.toUpperCase()}_SETUP_PATH`;
|
30 | }
|
31 | writeLogFile(msg) {
|
32 | mkdirSync(this.config.cacheDir, { recursive: true });
|
33 | const entry = `[${new Date().toISOString()}] ${msg}\n`;
|
34 | const fd = openSync(this.acLogfilePath, 'a');
|
35 | writeSync(fd, entry);
|
36 | }
|
37 | isBashOnWindows(shell) {
|
38 | return shell.endsWith('\\bash.exe');
|
39 | }
|
40 | }
|