xrefcli
Version:
CLI command for the searching through OpenEdge XREF
106 lines • 3.52 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const help_1 = require("../help");
const editor_1 = require("../editor");
class ShowCommand {
constructor(config) {
this.source = '';
this.tables = false;
this.jsonOutput = false;
this.xrefOutput = false;
this.openFile = false;
this.config = config;
}
execute(params) {
const promise = new Promise(resolve => {
const xreffiles = this.config.loadRepo(this.config.data.current);
const xreffile = xreffiles.filter(item => item.sourcefile === this.source)[0];
if (xreffile === undefined) {
console.error(`source '${this.source}' not in repo '${this.config.data.current}'`);
}
else {
if (this.openFile) {
this.openEditor(xreffile);
}
else {
this.generateOutput(xreffile);
}
}
resolve();
});
return promise;
}
validate(params) {
const options = params['options'];
if (options['help'] === true) {
const help = new help_1.Help();
help.showCommand();
process.exit(0);
}
const source = options['source'];
if (source === undefined) {
console.error('Error: a source name should be provided');
return false;
}
this.source = source;
const tables = options['tables'];
if (tables === true) {
this.tables = true;
}
if (options['json'] === true) {
this.jsonOutput = true;
}
if (options['xref'] === true) {
this.xrefOutput = true;
}
if (options['open'] === true) {
this.openFile = true;
}
return true;
}
openEditor(xreffile) {
const editor = new editor_1.Editor(this.config);
if (this.xrefOutput) {
editor.open([xreffile.xreffile]);
}
else {
editor.openContent(JSON.stringify(xreffile, undefined, 2));
}
}
generateOutput(xreffile) {
if (this.xrefOutput) {
const content = fs.readFileSync(xreffile.xreffile);
console.log(content.toString());
}
else {
if (!this.tables) {
console.log(JSON.stringify(xreffile, undefined, 2));
}
else {
if (this.jsonOutput) {
console.log(JSON.stringify(xreffile.tablenames, undefined, 2));
}
else {
xreffile.tables.forEach(table => {
const crdString = '[' +
(table.isCreated ? 'C' : ' ') +
(table.isUpdated ? 'U' : ' ') +
(table.isDeleted ? 'D' : ' ') + '] ' +
table.name;
console.log(crdString);
});
}
}
}
}
}
exports.ShowCommand = ShowCommand;
//# sourceMappingURL=show.js.map