Skip to content

Commit ba3d65a

Browse files
author
Matt Willer
authored
Fix duplicate execution during bulk input on delegated command (#133)
Commands that delegate to other commands were passing the bulk input flag through to the subcommand. Since the command being delegated to is executed in a way that includes re-initialization, this would re-run the entire bulk input again for each entry in the bulk input file. To fix this, that flag is now filtered out when running each command for the bulk input file, to ensure that no such recursion is possible.
1 parent 8fc2023 commit ba3d65a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/box-command.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,14 @@ class BoxCommand extends Command {
398398
// Include flag values from command line first; they'll automatically
399399
// be overwritten/combined with later values by the oclif parser
400400
Object.keys(this.flags)
401+
.filter(flag => flag !== 'bulk-file-path') // Remove the bulk file path flag so we don't recurse!
401402
.forEach(flag => this._addFlagToArgv(flag, this.flags[flag]));
402403

403404
// Include all flag values from bulk input, which will override earlier ones
404405
// from the command line
405-
bulkData.filter(o => o.type === 'flag')
406+
bulkData
407+
// Remove the bulk file path flag so we don't recurse!
408+
.filter(o => o.type === 'flag' && o.fieldKey !== 'bulk-file-path')
406409
.forEach(o => this._addFlagToArgv(o.fieldKey, o.value));
407410

408411
DEBUG.execute('Executing in bulk mode argv: %O', this.argv);

test/commands/bulk.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,51 @@ describe('Bulk', () => {
292292
'--token=test'
293293
])
294294
.it('should ignore CSV keys that do not map to valid args or flags');
295+
296+
let folderCollabInput = path.join(__dirname, '..', 'fixtures/bulk/folder_collab_input.csv');
297+
test
298+
.nock(TEST_API_ROOT, api => api
299+
.post('/2.0/collaborations', {
300+
item: {
301+
type: 'folder',
302+
id: '11111',
303+
},
304+
accessible_by: {
305+
type: 'user',
306+
login: 'mario@example.com',
307+
}
308+
})
309+
.reply(200, {})
310+
.post('/2.0/collaborations', {
311+
item: {
312+
type: 'folder',
313+
id: '22222',
314+
},
315+
accessible_by: {
316+
type: 'user',
317+
login: 'wario@example.com'
318+
}
319+
})
320+
.reply(200, {})
321+
.post('/2.0/collaborations', {
322+
item: {
323+
type: 'folder',
324+
id: '33333',
325+
},
326+
accessible_by: {
327+
type: 'user',
328+
login: 'peach@example.com'
329+
}
330+
})
331+
.reply(200, {})
332+
)
333+
.stdout()
334+
.command([
335+
'folders:collaborations:add', // @NOTE: This command delegates to collaborations:add
336+
`--bulk-file-path=${folderCollabInput}`,
337+
'--token=test'
338+
])
339+
.it('should not run duplicate commands when delegating to another command');
295340
});
296341

297342
describe('JSON Input', () => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
id,login
2+
11111,mario@example.com
3+
22222,wario@example.com
4+
33333,peach@example.com

0 commit comments

Comments
 (0)