ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
59 lines (58 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
require("reflect-metadata");
const command_1 = require("@oclif/command");
const git_1 = require("../wrapper/git");
const chalk = require('chalk');
const inquirer = require("inquirer");
class default_1 extends command_1.Command {
constructor() {
super(...arguments);
this.localBranches = [];
this.remoteBranches = [];
this.branchesList = [];
this.searchRemoteBranches = (answers, input) => {
const searchResults = this.remoteBranches.filter(branch => branch.indexOf(input) > 0);
return Promise.resolve(searchResults ? searchResults : answers);
};
this.searchLocalBranches = (_answers, input) => {
const searchResults = this.localBranches.filter(branch => branch.indexOf(input) > 0);
return Promise.resolve(searchResults);
};
this.getName = (branch) => {
return branch.isCurrent
? chalk.green(`${branch.name} (current)`)
: branch.name;
};
this.getType = (branch) => {
let branchType = branch.isLocal ? 'Local' : 'Remote';
if (branch.isCurrent) {
branchType = chalk.green(branchType);
}
return branchType;
};
}
runHelper() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt'));
if (this.requireRemoteBranches()) {
yield git_1.GitFacade.syncRemoteBranches();
}
this.branchesList = yield git_1.GitFacade.listBranches();
for (let branch of this.branchesList) {
if (branch.isLocal) {
this.localBranches.push(branch.name);
}
else {
this.remoteBranches.push(branch.name);
}
}
yield this.preformBranchOperation(yield this.getSelectedBranch());
});
}
requireRemoteBranches() {
return true;
}
}
exports.default = default_1;