UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

102 lines 4.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrgCmd = void 0; const generic_1 = require("./generic"); const command_1 = require("../cli/command"); const options_1 = require("./options"); const functions_1 = require("../util/functions"); const resolver_1 = require("./resolver"); const objects_1 = require("../util/objects"); class OrgCmd extends command_1.Command { constructor() { super(...arguments); this.command = 'org'; this.describe = 'Manage organizations'; } builder(yargs) { const resolver = (0, resolver_1.kindResolver)('org'); const opts = [options_1.withProfileOptions, options_1.withStandardOptions]; const commandName = 'organization'; const commandNamePlural = 'organizations'; const commandNameA = 'an organization'; return (yargs .demandCommand() .version(false) .help() // generic .command(new generic_1.Get(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Edit(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Query(commandNamePlural, resolver, undefined, ...opts).toYargs()) .command(new generic_1.Eventlog(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Tag(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Patch(commandName, resolver, ...opts).toYargs()) .command(new generic_1.ListPermissions(commandNameA, resolver, ...opts).toYargs()) .command(new generic_1.ViewAccessReport(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Update(commandName, resolver, [ { path: 'description', }, { path: 'tags.<key>', }, ], ...opts).toYargs()) // specific .command(new Create().toYargs())); } handle() { } } exports.OrgCmd = OrgCmd; class Create extends command_1.Command { constructor() { super(); this.command = 'create'; this.describe = 'Create a new organization'; } withCreateOptions(yargs) { return yargs.options({ accountId: { describe: 'Id of the billing account', requiresArg: true, demandOption: true, }, name: { describe: 'Name of the new organization', requiresArg: true, demandOption: true, }, description: { alias: 'desc', requiresArg: true, describe: 'Optional description, defaults to the name if not set', }, invitee: { describe: 'Emails of users to invite to the org as superuser(admin)', requiresArg: true, demandOption: true, multiple: true, }, }); } builder(yargs) { return (0, functions_1.pipe)( // this.withCreateOptions, generic_1.withTagOptions, options_1.withProfileOptions, options_1.withStandardOptions)(yargs); } async handle(args) { var _a; const baseUrl = (await this.session.discovery).endpoints['billing-ng']; const link = `${baseUrl}/account/${args.accountId}/org`; const body = { org: { name: args.name, description: args.description, }, invitees: [(_a = this.session.profile.authInfo) === null || _a === void 0 ? void 0 : _a.email, ...(0, objects_1.toArray)(args.invitee)], }; await this.client.post(link, body); const orgResolver = (0, resolver_1.kindResolver)('org'); const data = await this.client.get(orgResolver.resourceLink(args.name, this.session.context)); this.session.outFormat(data); } } //# sourceMappingURL=org.js.map