xrefcli
Version:
CLI command for the searching through OpenEdge XREF
141 lines • 5.02 kB
JavaScript
"use strict";
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 xrefparser_1 = require("xrefparser");
const help_1 = require("../help");
const editor_1 = require("../editor");
const path = __importStar(require("path"));
class SearchCommand {
constructor(config) {
this.reponame = '';
this.batch = false;
this.openSources = false;
this.jsonOutput = false;
this.config = config;
}
execute(params) {
const promise = new Promise(resolve => {
this.search();
resolve();
});
return promise;
}
search() {
const repo = this.config.getRepo(this.reponame);
const xreffiles = this.config.loadRepo(this.reponame);
const searcher = new xrefparser_1.Searcher(xreffiles);
let result = [];
if (this.field !== undefined) {
result = searcher.getFieldReferences(this.field, this.table, this.hasUpdates);
}
else if (this.table !== undefined) {
result = searcher.getTableReferences(this.table, this.hasCreates, this.hasUpdates, this.hasDeletes);
}
else if (this.db !== undefined) {
result = searcher.getDatabaseReferences(this.db);
}
if (this.openSources) {
const editor = new editor_1.Editor(this.config);
editor.open(result.map(item => repo.srcroot + path.sep + item.sourcefile));
}
else {
if (this.jsonOutput) {
console.log(JSON.stringify(result.map(item => item.sourcefile), undefined, 2));
}
else {
result.map(item => item.sourcefile).forEach(source => {
console.log(source);
});
}
if (!this.batch) {
console.log('count=', result.length);
}
}
}
validate(params) {
const options = params['options'];
if (options['help'] === true) {
const help = new help_1.Help();
help.searchCommand();
process.exit(0);
}
let reponame = options['name'];
if (reponame === undefined) {
if (this.config.data.current === undefined) {
console.error('Error: no repo specified, no current repo');
return false;
}
else {
reponame = this.config.data.current;
}
}
this.field = options['field'];
if (this.field === null) {
console.error('Field name for --field option needs to be specified');
return false;
}
this.table = options['table'];
if (this.table === null) {
console.error('Table name for --table option needs to be specified');
return false;
}
this.db = options['db'];
if (this.db === null) {
console.error('Database name for --db option needs to be specified');
return false;
}
this.class = options['class'];
if (this.class === null) {
console.error('Class name for --class option needs to be specified');
return false;
}
this.method = options['method'];
if (this.method === null) {
console.error('Method name for --method option needs to be specified');
return false;
}
this.interface = options['interface'];
if (this.interface === null) {
console.error('Interface name for --interface option needs to be specified');
return false;
}
this.hasCreates = this.parseCrudValue(options['create']);
this.hasUpdates = this.parseCrudValue(options['update']);
this.hasDeletes = this.parseCrudValue(options['delete']);
if (options['batch'] === true) {
this.batch = true;
}
if (options['open'] === true) {
this.openSources = true;
}
if (options['json'] === true) {
this.jsonOutput = true;
}
this.reponame = reponame;
return true;
}
parseCrudValue(value) {
if (value !== undefined) {
// the default value = true, so '--update' and '--update true' are the same
if (value === null) {
value = 'true';
}
value = value.toLowerCase();
if (value === 'true' || value === 'yes') {
return true;
}
else if (value === 'false' || value === 'no') {
return false;
}
}
return undefined;
}
}
exports.SearchCommand = SearchCommand;
//# sourceMappingURL=search.js.map