All files / api-build/commands update.js

84.21% Statements 16/19
66.67% Branches 4/6
50% Functions 2/4
82.35% Lines 14/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x             1x   1x   1x 1x 1x 1x 1x   1x   1x 5x 4x   4x       4x                          
module.exports.usage = `Update the used version of this service
 
Usage: api update <service> [<version>] [--team <team>]
 
The version is optional, and will by default update you to the latest.
--team is used to designate which team you would like to update
`;
module.exports.weight = 5;
 
module.exports.category = 'utility';
 
require('colors');
const createEnquirer = require('../lib/enquirer');
const request = require('../lib/request');
const console = require('../utils/console');
const { prefixName } = require('../lib/invoke');
 
const enquirer = createEnquirer();
 
module.exports.run = (args, opts) => {
  if (!args[1]) throw new Error('Please include a service you want to upgrade!');
  if (!args[2]) console.log('No version specified, updating to latest');
 
  return request.put(`/services/${prefixName(args[1])}/update`, {
    json: { version: args[2], team: opts.team },
    defaultErrorHandler: false,
  }).then((s) => {
    console.log(`${args[1]} updated to version ${s.version.green}`);
  }).catch((e) => {
    if (e.error.code === 'TeamSelectionRequired') {
      enquirer.ask([{
        type: 'list',
        name: 'team',
        message: 'Which team should be updated?',
        choices: e.error.data.teams,
      }]).then(results => module.exports.run(args, results));
    }
  });
};