@controlplane/cli
Version:
Control Plane Corporation CLI
74 lines • 2.55 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountCmd = void 0;
const _ = require("lodash");
const generic_1 = require("./generic");
const command_1 = require("../cli/command");
const options_1 = require("./options");
const functions_1 = require("../util/functions");
const resultFetcher_1 = require("../rest/resultFetcher");
const objects_1 = require("../util/objects");
class AccountCmd extends command_1.Command {
constructor() {
super(...arguments);
this.command = 'account';
this.describe = 'Manage accounts';
}
builder(yargs) {
return yargs.demandCommand().version(false).help().command(new Get().toYargs());
}
handle() { }
}
exports.AccountCmd = AccountCmd;
class Get extends command_1.Command {
constructor() {
super();
this.command = 'get [ref...]';
this.describe = 'Get accounts by id or list accounts';
}
builder(yargs) {
return (0, functions_1.pipe)(
//
generic_1.withMultipleRefs, options_1.withProfileOptions, options_1.withStandardOptions)(yargs);
}
async list(args) {
const baseUrl = (await this.session.discovery).endpoints['billing-ng'];
const link = `${baseUrl}/account`;
const body = await this.client.get(link);
await (0, resultFetcher_1.fetchPages)(this.client, this.session.format.max, body);
this.session.outFormat(body);
}
async get(args) {
var _a;
const baseUrl = (await this.session.discovery).endpoints['billing-ng'];
args.ref = _.uniq((0, objects_1.toArray)(args.ref));
if (((_a = args.ref) === null || _a === void 0 ? void 0 : _a.length) == 1) {
const link = `${baseUrl}/account/${args.ref[0]}`;
const body = await this.client.get(link);
this.session.outFormat(body);
return;
}
const accumulator = {
kind: 'list',
itemKind: 'account',
items: [],
links: [],
};
for (let ref of args.ref) {
const link = `${baseUrl}/${ref}`;
const body = await this.client.get(link);
accumulator.items.push(body);
}
if (accumulator.items.length > 0) {
this.session.outFormat(accumulator);
}
}
async handle(args) {
if (_.isEmpty(args.ref)) {
await this.list(args);
return;
}
await this.get(args);
}
}
//# sourceMappingURL=account.js.map
;