generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.ts
89 lines (81 loc) · 3.62 KB
/
delete.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
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
/*
* 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, SfdxError } from '@salesforce/core';
import AutoInstall from '../../../../lib/analytics/autoinstall/autoinstall';
import {
DEF_APP_CREATE_UPDATE_TIMEOUT,
DEF_POLLING_INTERVAL,
MIN_POLLING_INTERVAL
} from '../../../../lib/analytics/constants';
import { throwWithData } from '../../../../lib/analytics/utils';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/analytics', 'autoinstall');
export default class Delete extends SfdxCommand {
public static description = messages.getMessage('deleteCommandDescription');
public static longDescription = messages.getMessage('deleteCommandLongDescription');
public static examples = ['$ sfdx analytics:autoinstall:app:delete -f folderid'];
protected static flagsConfig = {
folderid: flags.id({
char: 'f',
required: true,
description: messages.getMessage('folderidFlagDescription'),
longDescription: messages.getMessage('folderidFlagLongDescription')
}),
async: flags.boolean({
char: 'a',
description: messages.getMessage('appDeleteAsyncDescription'),
longDescription: messages.getMessage('appDeleteAsyncLongDescription')
}),
wait: flags.number({
char: 'w',
description: messages.getMessage('autoInstallWaitDescription'),
longDescription: messages.getMessage('autoInstallWaitLongDescription', [DEF_APP_CREATE_UPDATE_TIMEOUT]),
min: 0,
default: DEF_APP_CREATE_UPDATE_TIMEOUT
}),
pollinterval: flags.number({
char: 'p',
description: messages.getMessage('autoInstallPollIntervalDescription'),
longDescription: messages.getMessage('autoInstallPollIntervalLongDescription', [DEF_POLLING_INTERVAL]),
min: MIN_POLLING_INTERVAL,
default: DEF_POLLING_INTERVAL
})
};
protected static requiresUsername = true;
protected static requiresProject = false;
public async run() {
const autoinstall = new AutoInstall(this.org as Org);
const autoInstallId = await autoinstall.delete(this.flags.folderid as string);
if (this.flags.async || this.flags.wait <= 0) {
this.ux.log(messages.getMessage('appDeleteRequestSuccess', [autoInstallId]));
} else if (autoInstallId) {
// otherwise start polling the request
const finalRequest = await autoinstall.pollRequest(autoInstallId, {
timeoutMs: this.flags.wait * 60 * 1000,
pauseMs: this.flags.pollinterval as number,
timeoutMessage: r =>
throwWithData(messages.getMessage('requestPollingTimeout', [autoInstallId, r?.requestStatus || '']), r),
ux: this.ux,
startMesg: messages.getMessage('startRequestPolling', [autoInstallId])
});
const status = finalRequest.requestStatus?.toLocaleLowerCase();
if (status === 'success') {
this.ux.log(messages.getMessage('appDeleteSuccess', [finalRequest.folderId, autoInstallId]));
return finalRequest;
} else if (status === 'cancelled') {
throwWithData(messages.getMessage('requestCancelled', [autoInstallId]), finalRequest);
} else {
throwWithData(messages.getMessage('appDeleteFailed', [autoInstallId]), finalRequest);
}
} else {
// we should always get an auto-install-request id back, but fail if we don't
throw new SfdxError(messages.getMessage('appDeleteFailed', ['']));
}
return autoInstallId;
}
}