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

box / boxcli / 10810816048

11 Sep 2024 11:36AM CUT coverage: 86.569% (-0.05%) from 86.616%
10810816048

Pull #542

github

web-flow
Merge a647aad97 into 0ed1618f5
Pull Request #542: docs: Add examples to file/folder metadata commands

1191 of 1536 branches covered (77.54%)

Branch coverage included in aggregate %.

4 of 4 new or added lines in 4 files covered. (100.0%)

1 existing line in 1 file now uncovered.

4281 of 4785 relevant lines covered (89.47%)

310.32 hits per line

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

81.03
/src/commands/files/zip.js
1
'use strict';
2

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

9
class FilesZipCommand extends BoxCommand {
10
        async run() {
11
                const { flags, args } = this.parse(FilesZipCommand);
40✔
12

13
                let fileName = args.name;
40✔
14
                if (!fileName.includes('.zip')) {
40!
15
                        fileName += '.zip';
×
16
                }
17

18
                let filePath;
19

20
                if (flags.destination) {
40✔
21
                        await utils.checkDir(flags.destination, flags['create-path']);
16✔
22
                        filePath = path.join(flags.destination, fileName);
16✔
23
                } else {
24
                        filePath = path.join(this.settings.boxDownloadsFolderPath, fileName);
24✔
25
                }
26

27
                /* eslint-disable no-sync */
28
                if (!flags.overwrite && fs.existsSync(filePath)) {
40✔
29
                /* eslint-enable no-sync */
30

31
                        if (flags.overwrite === false) {
8!
32
                                this.info(`Downloading the file will not occur because the file ${filePath} already exists, and the --no-overwrite flag is set.`);
8✔
33
                                return;
8✔
34
                        }
35

36
                        let shouldOverwrite = await this.confirm(`File ${filePath} already exists — overwrite?`);
×
37

38
                        if (!shouldOverwrite) {
×
39
                                return;
×
40
                        }
41
                }
42

43
                let output = fs.createWriteStream(filePath);
32✔
44

45
                let downloadStatus;
46
                let outputFinished = false;
32✔
47
                /* eslint-disable promise/avoid-new */
48
                await new Promise((resolve, reject) => {
32✔
49
                        /* eslint-disable promise/always-return */
50
                        this.client.files.downloadZip(fileName, flags.item, output).then((status) => {
32✔
51
                                downloadStatus = status;
32✔
52
                                if (outputFinished) {
32!
53
                                        resolve();
32✔
54
                                }
55
                        })
56
                        .catch(reject);
57
                        output.on('close', () => {
32✔
58
                                output.close();
32✔
59
                                outputFinished = true;
32✔
60
                                if (downloadStatus) {
32!
UNCOV
61
                                        resolve();
×
62
                                }
63
                        });
64
                        output.on('error', reject);
32✔
65
                });
66
                await this.output(downloadStatus);
32✔
67
        }
68
}
69

70
FilesZipCommand.description = 'Create a zip of multiple files and folders and download it';
8✔
71
FilesZipCommand.examples = ['box files:zip sample_file.zip --item=file:12421 --item=folder:48291'];
8✔
72
FilesZipCommand._endpoint = 'zip_downloads';
8✔
73

74
FilesZipCommand.flags = {
8✔
75
        ...BoxCommand.flags,
76
        destination: flags.string({
77
                description: 'The destination folder to write the zip file to',
78
                parse: utils.parsePath,
79
        }),
80
        item: flags.string({
81
                description:
82
                        'Files or folders to be part of zip in the form type:ID (i.e. file:1374652)',
83
                multiple: true,
84
                required: true,
85
                parse(val) {
86
                        let splitVal = val.split(':');
160✔
87
                        return { type: splitVal[0], id: splitVal[1] };
160✔
88
                },
89
        }),
90
        'create-path': flags.boolean({
91
                description: 'Recursively creates a path to a directory if it does not exist',
92
                allowNo: true,
93
                default: true,
94
        }),
95
        overwrite: flags.boolean({
96
                description: 'Overwrite a zip file if it already exists',
97
                allowNo: true
98
        }),
99
};
100

101
FilesZipCommand.args = [
8✔
102
        {
103
                name: 'name',
104
                required: true,
105
                hidden: false,
106
                description: 'Name of the zip to be created and downloaded',
107
        }
108
];
109

110
module.exports = FilesZipCommand;
8✔
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