UNPKG

@controlplane/cli

Version:

Control Plane Corporation CLI

122 lines 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskCmd = 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 resolver_1 = require("./resolver"); const resultFetcher_1 = require("../rest/resultFetcher"); const query_1 = require("./query"); const objects_1 = require("../util/objects"); class TaskCmd extends command_1.Command { constructor() { super(...arguments); this.command = 'task'; this.describe = 'Manage pending tasks'; } builder(yargs) { const resolver = (0, resolver_1.kindResolver)('task'); const opts = [options_1.withProfileOptions, options_1.withStandardOptions, options_1.withOrgOptions]; const taskSchema = { props: [...query_1.defaultProps, 'type', 'status', 'targetEmail', 'creatorLink'], }; // const commandName = 'task'; const commandNamePlural = 'tasks'; const commandNameA = 'a task'; return (yargs .demandCommand() .version(false) .help() // generic .command(new generic_1.ListPermissions(commandNameA, resolver, ...opts).toYargs()) .command(new generic_1.Get(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Delete(commandNamePlural, resolver, ...opts).toYargs()) .command(new generic_1.Query(commandNamePlural, resolver, taskSchema, ...opts).toYargs()) // specific .command(new GetMine().toYargs()) .command(new Complete().toYargs())); } handle() { } } exports.TaskCmd = TaskCmd; class Complete extends command_1.Command { constructor() { super(); this.command = 'complete <ref>'; this.describe = 'Complete the referenced task'; } withCompleteOptions(yargs) { return yargs.options({ answer: { describe: 'Accept or reject referenced task', requiresArg: true, demandOption: true, choices: ['accept', 'reject'], }, }); } builder(yargs) { return (0, functions_1.pipe)( // generic_1.withSingleRef, this.withCompleteOptions, options_1.withProfileOptions, options_1.withStandardOptions)(yargs); } async handle(args) { const body = { answer: args.answer, }; const data = await this.client.post(`/task/${args.ref}`, body); this.session.outFormat(data); } } class GetMine extends command_1.Command { constructor() { super(); this.command = 'get-mine [ref...]'; this.aliases = ['mine']; this.describe = 'Retrieve one or more referenced tasks for the current or overridden profile'; } builder(yargs) { return (0, functions_1.pipe)( // generic_1.withMultipleRefs, options_1.withProfileOptions, options_1.withStandardOptions)(yargs); } async list() { const link = '/task/-forme'; const body = await this.client.get(link); await (0, resultFetcher_1.fetchPages)(this.client, this.session.format.max, body); this.session.outFormat(body); } async handle(args) { if (_.isEmpty(args.ref)) { await this.list(); return; } const accumulator = { kind: 'list', itemKind: 'task', items: [], links: [], }; let failures = []; args.ref = _.uniq((0, objects_1.toArray)(args.ref)); for (let ref of args.ref) { try { const link = `/task/${ref}`; const body = await this.client.get(link); accumulator.items.push(body); } catch (e) { failures.push(e); } } if (accumulator.items.length > 0) { this.session.outFormat(accumulator); } if (failures.length > 0) { this.session.abort({ error: failures }); } } } //# sourceMappingURL=task.js.map