• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / boxcli / 4025218550

pending completion
4025218550

Pull #456

github

GitHub
Merge 5e271050e into 34aff89ac
Pull Request #456: fix: Fix unit tests

1081 of 1391 branches covered (77.71%)

Branch coverage included in aggregate %.

3965 of 4452 relevant lines covered (89.06%)

483.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/src/commands/configure/environments/update.js
1
'use strict';
2

3
const BoxCommand = require('../../../box-command');
12✔
4
const { flags } = require('@oclif/command');
12✔
5
const fs = require('fs');
12✔
6
const BoxCLIError = require('../../../cli-error');
12✔
7
const utils = require('../../../util');
12✔
8

9
class EnvironmentsUpdateCommand extends BoxCommand {
10
        async run() {
11
                const { flags, args } = this.parse(EnvironmentsUpdateCommand);
×
12
                let environmentsObj = await this.getEnvironments();
×
13
                let environment = environmentsObj.environments[args.name || environmentsObj.default];
×
14

15
                if (!environment) {
×
16
                        this.error('There is no environment with this name');
×
17
                        return;
×
18
                }
19

20
                if (flags['config-file-path']) {
×
21
                        let configObj;
22
                        try {
×
23
                                /* eslint-disable no-sync */
24
                                configObj = JSON.parse(fs.readFileSync(flags['config-file-path'], 'utf8'));
×
25
                                /* eslint-enable no-sync */
26
                        } catch (ex) {
27
                                throw new BoxCLIError(`Could not read environment config file ${flags['config-file-path']}`, ex);
×
28
                        }
29

30
                        utils.validateConfigObject(configObj);
×
31

32
                        if (!configObj.boxAppSettings.appAuth.privateKey && !flags['private-key-path'] && environment.hasInLinePrivateKey) {
×
33
                                throw new BoxCLIError('Environment must specify private key in config file or via --private-key-path');
×
34
                        }
35
                        if (configObj.boxAppSettings.appAuth.privateKey) {
×
36
                                environment.privateKeyPath = '';
×
37
                                environment.hasInLinePrivateKey = true;
×
38
                        }
39
                        environment.boxConfigFilePath = flags['config-file-path'];
×
40
                }
41
                if (flags.name) {
×
42
                        environment.name = flags.name;
×
43
                }
44
                if (flags['private-key-path']) {
×
45
                        environment.privateKeyPath = flags['private-key-path'];
×
46
                        environment.hasInLinePrivateKey = false;
×
47
                }
48
                if (flags['user-id']) {
×
49
                        environment.defaultAsUserId = flags['user-id'];
×
50
                        environment.useDefaultAsUser = true;
×
51
                }
52

53
                if (flags.hasOwnProperty('cache-tokens')) {
×
54
                        environment.cacheTokens = flags['cache-tokens'];
×
55
                }
56

57
                await this.updateEnvironments(environmentsObj);
×
58
                await this.output(environment);
×
59
        }
60
}
61

62
// @NOTE: This command does not require a client to be set up
63
EnvironmentsUpdateCommand.noClient = true;
12✔
64

65
EnvironmentsUpdateCommand.description = 'Update a Box environment';
12✔
66

67
EnvironmentsUpdateCommand.flags = {
12✔
68
        ...BoxCommand.minFlags,
69
        'config-file-path': flags.string({
70
                description: 'Provide a file path to configuration file',
71
                parse: utils.parsePath,
72
        }),
73
        name: flags.string({ description: 'New name of the environment' }),
74
        'private-key-path': flags.string({
75
                description: 'Provide a file path to application private key',
76
                parse: utils.parsePath,
77
        }),
78
        'user-id': flags.string({ description: 'Store a default user ID to use with the session commands. A default user ID can be stored for each Box environment' }),
79
        'cache-tokens': flags.boolean({
80
                description: 'Enable token caching, which significantly improves performance. Run with --no-cache-tokens and then --cache-tokens if your application config updates are not reflected in your requests.',
81
                allowNo: true,
82
        }),
83
};
84

85
EnvironmentsUpdateCommand.args = [
12✔
86
        {
87
                name: 'name',
88
                required: false,
89
                hidden: false,
90
                description: 'The name of the environment'
91
        }
92
];
93

94
module.exports = EnvironmentsUpdateCommand;
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc