/
set-current.js
53 lines (44 loc) · 1.36 KB
/
set-current.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const BoxCommand = require('../../../box-command');
const inquirer = require('inquirer');
class EnvironmentsSetCurrentCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(EnvironmentsSetCurrentCommand);
let environmentsObj = this.getEnvironments();
let name = args.name;
if (!name) {
let answers = await inquirer.prompt([
{
type: 'list',
name: 'environment',
message: 'Which environment?',
choices: Object.keys(environmentsObj.environments),
}
]);
name = answers.environment;
}
if (environmentsObj.environments.hasOwnProperty(name)) {
environmentsObj.default = name;
this.updateEnvironments(environmentsObj);
this.info(`The ${name} environment has been set as the default`);
} else {
this.error(`The ${name} environment does not exist`);
}
}
}
// @NOTE: This command does not require a client to be set up
EnvironmentsSetCurrentCommand.noClient = true;
EnvironmentsSetCurrentCommand.aliases = [ 'configure:environments:select' ];
EnvironmentsSetCurrentCommand.description = 'Set your current Box environment to use';
EnvironmentsSetCurrentCommand.flags = {
...BoxCommand.minFlags,
};
EnvironmentsSetCurrentCommand.args = [
{
name: 'name',
required: false,
hidden: false,
description: 'Name of the environment'
}
];
module.exports = EnvironmentsSetCurrentCommand;