UNPKG

fedapay-cli

Version:
76 lines (75 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const fedapay_1 = require("fedapay"); const base_1 = tslib_1.__importDefault(require("../base")); const tail_util_1 = tslib_1.__importDefault(require("../helpers/tail-util")); const dataparse_1 = tslib_1.__importDefault(require("../helpers/dataparse")); /** * Logs class extending Command Class */ class Logs extends base_1.default { async run() { const { flags } = this.parse(Logs); /** * @param string * api key value */ const apiKey = this.userConfig.read('secret_key', flags['api-key']); /** * @param string * environment type */ const environment = this.userConfig.read('environment', flags.environment); /** * Set Apikey and environment to connect to fedapay */ fedapay_1.FedaPay.setApiKey(apiKey); fedapay_1.FedaPay.setEnvironment(environment); const filters = dataparse_1.default.transform(flags.filters); if (flags.tail) { const queueOptions = await fedapay_1.Log.subscribe(); const mqUrl = this.userConfig.read('mq_url'); const tail = new tail_util_1.default(mqUrl, queueOptions); const keys = flags.dump ? [] : ['method', 'url', 'status']; tail.connect(filters, keys, (output) => { this.log(output); }); this.log('Waiting for logs...'); } else { this._help(); } } } exports.default = Logs; /** * @param string * Description of the command Logs. */ Logs.description = 'Manage FedaPay logs'; /** * @param string * Custom usage string for help * This overrides the default usage */ Logs.usage = 'logs:<operation> [parameters...]'; /** * @param string[] * Examples to add to help. * Each can be multiline. */ Logs.examples = [ 'logs:list', 'logs:retrieve --id=ID', ]; /** * @param object * Declaration of the command flags. */ Logs.flags = Object.assign(Object.assign({}, base_1.default.flags), { tail: command_1.flags.boolean({ char: 't', description: 'Tail logs', default: false }), dump: command_1.flags.boolean({ char: 'd', description: 'Dump log details', default: false }), filters: command_1.flags.string({ char: 'f', description: 'Filter the list of logs to tail.', multiple: true, }), help: command_1.flags.help({ char: 'h', description: 'Help for logs command.' }) });