UNPKG

buddyworks-cli

Version:

Command line tool for managing pipelines in Buddy Works

62 lines (54 loc) 1.59 kB
const api = require('../../api'); const output = require('../../output'); const config = require('../../config'); module.exports.command = 'retry [pipeline]'; module.exports.aliases = 't'; module.exports.describe = 'retry execution of a given pipeline'; module.exports.builder = { j: { default: false, alias: 'json', describe: 'Output json', type: 'boolean', }, t: { alias: 'token', describe: 'Token to authenticate request', type: 'string', }, u: { alias: 'url', describe: 'Base url for app (default: api.buddy.works)', type: 'string', }, w: { alias: 'workspace', describe: 'Name of a workspace in which run this command', type: 'string', }, p: { alias: 'project', describe: 'Name of a project in which run this command', type: 'string', }, }; module.exports.request = (args, done) => { api.getLastExecution(args, (err, obj) => { if (err) done(err); else if (!obj) done(new Error('Pipeline has no executions yet')); else if (obj.status !== 'FAILED' && obj.status !== 'TERMINATED') done(new Error('Pipeline last execution is not failed or terminated')); else api.retryPipeline(obj.id, args, done); }); }; module.exports.render = (args) => { let msg = 'Retrying pipeline\n'; msg += 'Check its status by running:\n\n'; msg += `buddy-cli pl i ${config.get(config.KEY_PIPELINE)}`; output.ok(args.json, msg); }; module.exports.handler = (args) => { exports.request(args, (err) => { if (err) output.error(args.json, err.message); else exports.render(args); }); };