-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathupdate.js
93 lines (82 loc) · 2.64 KB
/
update.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const BoxCommand = require('../../../box-command');
const { Flags, Args } = require('@oclif/core');
const utils = require('../../../util');
const OP_FLAGS = Object.freeze({
add: true,
copy: true,
move: true,
remove: true,
replace: true,
test: true,
});
class FoldersUpdateMetadataCommand extends BoxCommand {
async run() {
const { flags, args, raw } = await this.parse(FoldersUpdateMetadataCommand);
let updates = raw.filter(v => v.type === 'flag' && OP_FLAGS[v.flag]).map(op => {
let opName = op.flag;
let opData = flags[op.flag].shift();
return { op: opName, ...opData };
});
let templateKey = flags['template-key'];
let metadata = await this.client.folders.updateMetadata(args.id, flags.scope, templateKey, updates);
await this.output(metadata);
}
}
FoldersUpdateMetadataCommand.description = 'Update the metadata attached to a folder';
FoldersUpdateMetadataCommand.examples = ['box folders:metadata:update 22222 --template-key employeeRecord --replace department=Finance'];
FoldersUpdateMetadataCommand._endpoint = 'put_folders_id_metadata_id_id';
FoldersUpdateMetadataCommand.flags = {
...BoxCommand.flags,
scope: Flags.string({
description: 'The scope of the metadata template to update against',
default: 'enterprise',
}),
'template-key': Flags.string({
description: 'The key of the metadata template to update against',
required: true,
}),
add: Flags.string({
char: 'a',
description: 'Add a key to the metadata document; must be in the form key=value',
multiple: true,
parse: utils.parseMetadataOp,
}),
copy: Flags.string({
char: 'c',
description: 'Copy a metadata value to another key; must be in the form sourceKey>destinationKey',
multiple: true,
parse: utils.parseMetadataOp,
}),
move: Flags.string({
char: 'm',
description: 'Move a metadata value from one key to another; must be in the form sourceKey>destinationKey',
multiple: true,
parse: utils.parseMetadataOp,
}),
remove: Flags.string({
description: 'Remove a key from the metadata document',
multiple: true,
parse: utils.parseMetadataOp,
}),
replace: Flags.string({
description: 'Replace the value of an existing metadata key; must be in the form key=value',
multiple: true,
parse: utils.parseMetadataOp,
}),
test: Flags.string({
char: 't',
description: 'Test that a metadata key contains a specific value; must be in the form key=value',
multiple: true,
parse: utils.parseMetadataOp,
}),
};
FoldersUpdateMetadataCommand.args = {
id: Args.string({
name: 'id',
required: true,
hidden: false,
description: 'ID of the folder to update metadata on',
}),
};
module.exports = FoldersUpdateMetadataCommand;