xrefcli
Version:
CLI command for the searching through OpenEdge XREF
91 lines • 3.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const xrefparser_1 = require("xrefparser");
const help_1 = require("../help");
class ListCommand {
constructor(config) {
this.xreffiles = [];
this.outputJson = false;
this.dbPrefix = false;
this.outputType = 'tables';
this.config = config;
this.searcher = new xrefparser_1.Searcher();
}
execute(params) {
const promise = new Promise(resolve => {
this.xreffiles = this.config.loadRepo(this.config.data.current);
this.searcher.add(this.xreffiles);
switch (this.outputType) {
case 'tables':
this.outputTables();
break;
case 'dbs':
this.outputDatabases();
break;
}
resolve();
});
return promise;
}
validate(params) {
const options = params['options'];
if (options['help'] === true) {
const help = new help_1.Help();
help.listCommand();
process.exit(0);
}
if (options['tables'] === true && options['dbs'] === true) {
console.error('--tables and --dbs options cannot be combined');
return false;
}
if (options['dbs'] === true) {
this.outputType = 'dbs';
}
else {
// no processing of tables parameters now, it's the only (and therefor default) option
if (options['dbprefix'] === true) {
this.dbPrefix = true;
}
}
if (options['json'] === true) {
this.outputJson = true;
}
return true;
}
outputDatabases() {
let dbs = this.searcher.getDatabaseNames();
dbs = dbs.sort((a, b) => a < b ? -1 : 1);
if (this.outputJson) {
console.log(JSON.stringify(dbs, undefined, 2));
}
else {
dbs.forEach(db => {
console.log(db);
});
}
}
outputTables() {
const tables = this.searcher.getTableNames();
if (this.outputJson) {
console.log(JSON.stringify(tables, undefined, 2));
}
else {
if (!this.dbPrefix) {
const tableArray = [...new Set(tables.map(item => item.table))];
tableArray.sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : 1);
tableArray.forEach(tablename => {
console.log(tablename);
});
}
else {
const tableArray = [...new Set(tables.map(item => item.database + '.' + item.table))];
tableArray.sort((a, b) => a.toLowerCase() < b.toLowerCase() ? -1 : 1);
tableArray.forEach(tablename => {
console.log(tablename);
});
}
}
}
}
exports.ListCommand = ListCommand;
//# sourceMappingURL=list.js.map