generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.ts
63 lines (54 loc) · 2.47 KB
/
update.ts
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
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages, Org } from '@salesforce/core';
import Dashboard from '../../../lib/analytics/dashboard/dashboard';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/analytics', 'dashboard');
export default class Update extends SfdxCommand {
public static description = messages.getMessage('updateCommandDescription');
public static longDescription = messages.getMessage('updateCommandLongDescription');
public static examples = [
'$ sfdx analytics:dashboard:update -i dashboardId -y currentHistoryId',
'$ sfdx analytics:dashboard:update -i dashboardId -r'
];
protected static flagsConfig = {
dashboardid: flags.id({
char: 'i',
required: true,
description: messages.getMessage('dashboardIdFlagDescription'),
longDescription: messages.getMessage('dahsboardIdFlagLongDescription')
}),
currenthistoryid: flags.id({
char: 'y',
description: messages.getMessage('currentHistoryIdFlagDescription'),
longDescription: messages.getMessage('currentHistoryIdLongDescription')
}),
removecurrenthistory: flags.boolean({
char: 'r',
description: messages.getMessage('removeCurrentHistoryFlagDescription'),
longDescription: messages.getMessage('removeCurrentHistoryLongDescription')
})
};
protected static requiresUsername = true;
protected static requiresProject = false;
public async run() {
const dashboard = new Dashboard(this.org as Org);
// -h and -r are kind of exclusive, and, in the oclif flags, you can pass in neither,
// in which case we should should consider a missing or no -h to be the same as -r
const historyId = (!this.flags.removecurrenthistory && (this.flags.currenthistoryid as string)) || '';
const id = await dashboard.updateCurrentHistoryId(this.flags.dashboardid as string, historyId);
// If error occurs here fails out in the update call and reports back, otherwise success
// if we sent up an empty historyId, that's the same as -r
if (!historyId) {
this.ux.log(messages.getMessage('updateRemoveSuccess', []));
} else {
this.ux.log(messages.getMessage('updateSuccess', [historyId]));
}
return id;
}
}