generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
snapshot.ts
64 lines (57 loc) · 2.31 KB
/
snapshot.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
/*
* Copyright (c) 2020, 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 { EOL } from 'node:os';
import {
Flags,
SfCommand,
loglevel,
orgApiVersionFlagWithDeprecations,
requiredHubFlagWithDeprecations,
} from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import type { SaveResult, SaveError } from 'jsforce';
import { queryByNameOrId } from '../../../shared/snapshot.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'snapshot.delete');
// jsforce can return SaveError[] or never[]
const isSaveError = (error: SaveError): error is SaveError => error.message !== undefined;
export class SnapshotDelete extends SfCommand<SaveResult> {
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:snapshot:delete'];
public static readonly deprecateAliases = true;
public static readonly state = 'beta';
public static readonly flags = {
'target-dev-hub': requiredHubFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
loglevel,
snapshot: Flags.string({
char: 's',
summary: messages.getMessage('flags.snapshot.summary'),
description: messages.getMessage('flags.snapshot.description'),
required: true,
}),
};
public async run(): Promise<SaveResult> {
// resolve the query to an ID. This also verifies the snapshot exists in the org
const { flags } = await this.parse(SnapshotDelete);
const conn = flags['target-dev-hub'].getConnection(flags['api-version']);
const result = await queryByNameOrId(conn, flags.snapshot);
const deleteResult = await conn.sobject('OrgSnapshot').delete(result.Id);
if (deleteResult.success) {
this.logSuccess(messages.getMessage('success', [flags.snapshot]));
return deleteResult;
}
throw new Error(
deleteResult.errors
.filter(isSaveError)
.map((error) => error.message)
.join(EOL)
);
}
}