@heroku-cli/plugin-autocomplete
Version:
<!-- usage --> ```sh-session $ heroku plugins:install @heroku-cli/plugin-autocomplete $ heroku autocomplete ... ``` <!-- usagestop --> # Commands <!-- commands --> * [`heroku autocomplete [SHELL]`](#heroku-autocomplete-shell)
54 lines (53 loc) • 1.95 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@heroku-cli/command");
const fs = require("fs-extra");
const moment = require("moment");
const path = require("path");
const completions_1 = require("./completions");
class AutocompleteBase extends command_1.default {
errorIfWindows() {
if (this.config.windows) {
throw new Error('Autocomplete is not currently supported in Windows');
}
}
errorIfNotSupportedShell(shell) {
if (!['bash', 'zsh'].includes(shell)) {
throw new Error(`Currently ${shell} is not a supported shell for autocomplete`);
}
}
get autocompleteCacheDir() {
return path.join(this.config.cacheDir, 'autocomplete');
}
get completionsCacheDir() {
return path.join(this.config.cacheDir, 'autocomplete', 'completions');
}
get acLogfile() {
return path.join(this.config.cacheDir, 'autocomplete.log');
}
writeLogFile(msg) {
let entry = `[${moment().format()}] ${msg}\n`;
let fd = fs.openSync(this.acLogfile, 'a');
// @ts-ignore
fs.write(fd, entry);
}
findCompletion(name, id) {
if (this.blacklisted(name, id))
return;
if (completions_1.CompletionVariableArgsLookup[id])
return completions_1.CompletionMapping[completions_1.CompletionVariableArgsLookup[id]];
const alias = this.convertIfAlias(name);
if (completions_1.CompletionMapping[alias])
return completions_1.CompletionMapping[alias];
}
blacklisted(name, id) {
return completions_1.CompletionBlacklist[name] && completions_1.CompletionBlacklist[name].includes(id);
}
convertIfAlias(name) {
let alias = completions_1.CompletionAliases[name];
if (alias)
return alias;
return name;
}
}
exports.AutocompleteBase = AutocompleteBase;
;