Skip to content

Commit 63db0ac

Browse files
Fix command line flags for bulk commands (#183)
1 parent d1bd0f5 commit 63db0ac

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Added `--quiet` flag to suppress any non-error output to stderr
66
- Fixed a bug for the `--restrict-collaboration` flag for `box folders:update` where previously the flag would not restrict the collaborations when passed as true and would restrict collaborations when passed as false
77
- Added `box trash:restore` to restore a trashed item and `box trash:get` to get information on a trashed item
8+
- Fixed a bug where flags that can be specified multiple times in a single command could not be passed through the command line for bulk commands
89

910
## 2.4.0 [2019-08-29]
1011

src/box-command.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,17 @@ class BoxCommand extends Command {
401401
// be overwritten/combined with later values by the oclif parser
402402
Object.keys(this.flags)
403403
.filter(flag => flag !== 'bulk-file-path') // Remove the bulk file path flag so we don't recurse!
404-
.forEach(flag => this._addFlagToArgv(flag, this.flags[flag]));
404+
.forEach(flag => {
405+
// Some flags can be specified multiple times in a single command. For these flags, their value is an array of user inputted values.
406+
// For these flags, we iterate through their values and add each one as a separate flag to comply with oclif
407+
if (Array.isArray(this.flags[flag])) {
408+
(this.flags[flag]).forEach(value => {
409+
this._addFlagToArgv(flag, value);
410+
});
411+
} else {
412+
this._addFlagToArgv(flag, this.flags[flag]);
413+
}
414+
});
405415

406416
// Include all flag values from bulk input, which will override earlier ones
407417
// from the command line

test/commands/bulk.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,35 @@ describe('Bulk', () => {
200200
])
201201
.it('should permit keys that do not use flag punctuation');
202202

203+
let folderLockBody = {
204+
folder: {
205+
type: 'folder',
206+
id: '1243215'
207+
}
208+
};
209+
let folderLockBodyString = JSON.stringify(folderLockBody);
210+
let folderLockInputFilePath = path.join(__dirname, '../fixtures/bulk/input_manual_request_folder_lock.csv');
211+
let folderLockBodyFixture = getFixture('bulk/post_folders_lock.json');
212+
test
213+
.nock(TEST_API_ROOT, api => api
214+
.matchHeader('Content-Type', 'application/json;version=1')
215+
.matchHeader('Accept', 'application/json;version=1')
216+
.post('/2.0/folder_locks', folderLockBody)
217+
.reply(200, folderLockBodyFixture)
218+
)
219+
.stdout()
220+
.stderr()
221+
.command([
222+
'request',
223+
`--body=${folderLockBodyString}`,
224+
'--header=Content-Type: application/json;version=1',
225+
'--header=Accept: application/json;version=1',
226+
`--bulk-file-path=${folderLockInputFilePath}`,
227+
'--json',
228+
'--token=test'
229+
])
230+
.it('should allow flags that can be specified multiple times in a single command to be passed through the command line for bulk commands');
231+
203232
test
204233
.nock(TEST_API_ROOT, api => api
205234
.get('/2.0/search')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RESOURCE,method
2+
https://api.box.com/2.0/folder_locks,POST
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"folder": {
3+
"type": "folder",
4+
"id": "123",
5+
"sequence_id": "1",
6+
"etag": "1",
7+
"name": "locked_folder"
8+
},
9+
"id": "2648",
10+
"type": "folder_lock",
11+
"created_by": {
12+
"id": "1111",
13+
"type": "user"
14+
},
15+
"created_at": "2019-10-17T18:06:36Z",
16+
"lock_type": "freeze"
17+
}

0 commit comments

Comments
 (0)