generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathshape.ts
99 lines (85 loc) · 3.11 KB
/
shape.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
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (c) 2022, 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,
SfCommand,
requiredOrgFlagWithDeprecations,
orgApiVersionFlagWithDeprecations,
loglevel,
} from '@salesforce/sf-plugins-core';
import { Messages, SfError } from '@salesforce/core';
import { isShapeEnabled } from '../../../shared/orgShapeListUtils.js';
import utils, { DeleteAllResult } from '../../../shared/deleteUtils.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'shape.delete');
export type OrgShapeDeleteResult = {
orgId: string;
} & DeleteAllResult;
export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | undefined> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly aliases = ['force:org:shape:delete'];
public static readonly deprecateAliases = true;
public static readonly flags = {
'target-org': requiredOrgFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
loglevel,
'no-prompt': Flags.boolean({
char: 'p',
summary: messages.getMessage('flags.no-prompt.summary'),
aliases: ['noprompt'],
deprecateAliases: true,
}),
};
public async run(): Promise<OrgShapeDeleteResult | undefined> {
const { flags } = await this.parse(OrgShapeDeleteCommand);
const username = flags['target-org'].getUsername();
if (!username) throw new SfError('No username found for target-org');
const orgId = flags['target-org'].getOrgId();
if (!flags['no-prompt']) {
if (!(await this.confirm({ message: messages.getMessage('deleteCommandYesNo', [username]) }))) {
return;
}
}
const conn = flags['target-org'].getConnection(flags['api-version']);
if (!(await isShapeEnabled(conn))) {
throw messages.createError('noAccess', [username]);
}
const deleteRes = await utils.deleteAll(conn, username);
if (deleteRes.shapeIds.length === 0) {
this.info(messages.getMessage('noShapesHumanSuccess', [orgId]));
return;
}
if (deleteRes.failures.length > 0) {
setExitCode(68);
this.logSuccess(messages.getMessage('humanSuccess', [orgId]));
this.log('');
this.table({
data: deleteRes.failures,
columns: [
{ key: 'shapeId', name: 'Shape ID' },
{ key: 'message', name: 'Error Message' },
],
title: 'Failures',
});
} else if (deleteRes.failures.length === deleteRes.shapeIds.length) {
setExitCode(1);
} else {
setExitCode(0);
this.logSuccess(messages.getMessage('humanSuccess', [orgId]));
}
return {
orgId,
shapeIds: deleteRes.shapeIds,
failures: deleteRes.failures,
};
}
}
const setExitCode = (code: number): void => {
process.exitCode = code;
};