UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

90 lines 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserCmd = 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 objects_1 = require("../util/objects"); const query_1 = require("./query"); const resolver_1 = require("./resolver"); class UserCmd extends command_1.Command { constructor() { super(...arguments); this.command = 'user'; this.describe = 'Manage users'; } builder(yargs) { const resolver = (0, resolver_1.kindResolver)('user'); const schema = { props: [...query_1.defaultProps, 'idp', 'email'], }; const opts = [options_1.withOrgOptions, options_1.withStandardOptions]; const commandName = 'user'; const commandNamePlural = 'users'; const commandNameA = 'a user'; 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.Patch(commandName, resolver, ...opts).toYargs()) .command(new generic_1.Query(commandNamePlural, resolver, schema, ...opts).toYargs()) .command(new generic_1.Delete(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Eventlog(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.Tag(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Update(commandName, resolver, [ { path: 'tags.<key>', }, ], ...opts).toYargs()) // specific .command(new Invite(resolver).toYargs())); } handle() { } } exports.UserCmd = UserCmd; class Invite extends command_1.Command { constructor(resolve) { super(); this.resolve = resolve; this.command = 'invite'; this.describe = 'Invite users to the current or overridden organization'; } withInviteOptions(yargs) { return yargs.options({ email: { describe: 'Email address of the user to invite', requiresArg: true, demandOption: true, multiple: true, }, group: { describe: 'Primary group to add the user to after they accept an invitation', requiresArg: true, }, }); } builder(yargs) { return (0, functions_1.pipe)( // this.withInviteOptions, options_1.withOrgOptions, options_1.withStandardOptions)(yargs); } async handle(args) { let link = this.resolve.homeLink(this.session.context); link += '/-invite'; const body = { emails: (0, objects_1.toArray)(args.email).map(i => i.toLowerCase()), }; if (args.group) { body.groupLink = (0, resolver_1.resolveToLink)('group', args.group, args); } const response = await this.client.post(link, body); this.session.outFormat(response); } } //# sourceMappingURL=user.js.map