fedapay-cli
Version:
A command-line tool for FedaPay
93 lines (92 loc) • 3.06 kB
JavaScript
"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 cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const payouts_1 = tslib_1.__importDefault(require("../payouts"));
/**
* PayoutsDelete Class
*/
class PayoutsDelete extends payouts_1.default {
async run() {
/**
* @param Object
* get the delete flags
*/
const { flags } = this.parse(PayoutsDelete);
/**
* @param string
* the api-key
*/
const apiKey = this.userConfig.read('secret_key', flags['api-key']);
/**
* @param String
* sandbox or live
*/
const environment = this.userConfig.read('environment', flags.environment);
/**
* @param integer
* id of the payout
*/
const id = flags.id;
/**
* connect to Fedapay with config set up
*/
fedapay_1.FedaPay.setApiKey(apiKey);
fedapay_1.FedaPay.setEnvironment(environment);
/**
* @param boolean
* true if the user set the --confirm flag or input yes in the terminal
*/
const confirm = flags.confirm || await cli_ux_1.default.confirm('Are you sure to continue? [Y/n]');
if (confirm) {
try {
cli_ux_1.default.action.start('Retrieving payout');
const payout = await fedapay_1.Payout.retrieve(id);
cli_ux_1.default.action.start('Deleting payout');
await payout.delete();
this.log(chalk_1.default.green('Payout delected successfully.'));
}
catch (error) {
this.error(error.message);
}
}
else {
this.log(chalk_1.default.yellow('Deletion canceled.'));
}
cli_ux_1.default.action.stop();
}
}
exports.default = PayoutsDelete;
/**
* @param string
* Description of payouts:delete command
*/
PayoutsDelete.description = 'Delete payout ressource';
/**
* @param Object
* delete command flags
*/
PayoutsDelete.flags = Object.assign(Object.assign({}, payouts_1.default.flags), { id: command_1.flags.integer({
description: 'The payout ID.',
required: true,
}), confirm: command_1.flags.boolean({
description: 'Skip the warning prompt and automatically confirm the command being entered.',
default: false,
char: 'c',
}), help: command_1.flags.help({ char: 'h', description: 'Help for payouts:delete.' }) });
/**
* @param string
* Set the command usage for help
*/
PayoutsDelete.usage = 'payouts:delete [options]';
/**
* @param string[]
* examples for the delete commands
*/
PayoutsDelete.examples = [
'payouts:delete --api-key=[API-KEY] --environment=[env] --id=[ID]',
'payouts:delete --api-key=[API-KEY] --environment=[env] --id=[ID] -c'
];