generated from salesforcecli/lerna-template
-
Notifications
You must be signed in to change notification settings - Fork 11
/
tree.ts
60 lines (52 loc) · 2.15 KB
/
tree.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
/*
* 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 { Messages } from '@salesforce/core';
import { SfCommand, Flags, arrayWithDeprecation } from '@salesforce/sf-plugins-core';
import { importFromPlan } from '../../../../api/data/tree/importPlan.js';
import { importFromFiles } from '../../../../api/data/tree/importFiles.js';
import { orgFlags } from '../../../../flags.js';
import { ImportResult } from '../../../../api/data/tree/importTypes.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-data', 'tree.import.beta');
/**
* Command that provides data import capability via the SObject Tree Save API.
*/
export default class Import extends SfCommand<ImportResult[]> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
// TODO: when you remove the beta state, put the force: aliases back in
public static readonly state = 'beta';
public static readonly flags = {
...orgFlags,
files: arrayWithDeprecation({
char: 'f',
summary: messages.getMessage('flags.files.summary'),
exactlyOne: ['files', 'plan'],
aliases: ['sobjecttreefiles'],
deprecateAliases: true,
}),
plan: Flags.file({
char: 'p',
summary: messages.getMessage('flags.plan.summary'),
exactlyOne: ['files', 'plan'],
exists: true,
}),
};
public async run(): Promise<ImportResult[]> {
const { flags } = await this.parse(Import);
const conn = flags['target-org'].getConnection(flags['api-version']);
const results = flags.plan ? await importFromPlan(conn, flags.plan) : await importFromFiles(conn, flags.files);
this.styledHeader('Import Results');
this.table(results, {
refId: { header: 'Reference ID' },
type: { header: 'Type' },
id: { header: 'ID' },
});
return results;
}
}