fedapay-cli
Version:
A command-line tool for FedaPay
93 lines (92 loc) • 3.18 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 customers_1 = tslib_1.__importDefault(require("../customers"));
const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
/**
* CustomersDelete class extending the superClass Customers
*/
class CustomersDelete extends customers_1.default {
async run() {
/**
* @param object
* get flags value
*/
const { flags } = this.parse(CustomersDelete);
/**
* @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);
/**
* @param number
* store the customer id
*/
const id = flags.id;
/**
* Set Apikey and environment to connect to fedapay
*/
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 customer');
const customer = await fedapay_1.Customer.retrieve(id);
cli_ux_1.default.action.start('Deleting customer');
customer.delete();
this.log(chalk_1.default.green('Customer 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 = CustomersDelete;
/**
* @param string
* Description of the command Customer:delete
*/
CustomersDelete.description = 'Delete a customer.';
/**
* @param object
* Declaration of the command flags
*/
CustomersDelete.flags = Object.assign(Object.assign({}, customers_1.default.flags), { id: command_1.flags.integer({
description: 'The customer ID.',
required: true
}), confirm: command_1.flags.boolean({
description: 'Skip the warning prompt and automatically confirm the command being entered.',
char: 'c',
default: false
}), help: command_1.flags.help({ char: 'h', description: 'Help for customers:delete.' }) });
/**
* @param string
* Set the command usage for help
*/
CustomersDelete.usage = 'customers:delete [options]';
/**
* @param string[]
* some examples of the custommers delete use for help
*/
CustomersDelete.examples = [
'customers:delete --api-key=[API-KEY] --environment=[env] --id=[ID]',
'customers:delete --api-key=[API-KEY] --environment=[env] --id=[ID] -c',
];