generated from salesforcecli/lerna-template
-
Notifications
You must be signed in to change notification settings - Fork 14
/
tree.ts
67 lines (60 loc) · 2.3 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
61
62
63
64
65
66
67
/*
* 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 } 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 type { ImportResult } from '../../../api/data/tree/importTypes.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-data', 'tree.import');
/**
* 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');
public static readonly aliases = ['force:data:tree:import', 'data:import:beta:tree'];
public static readonly deprecateAliases = true;
public static readonly flags = {
...orgFlags,
files: Flags.string({
char: 'f',
summary: messages.getMessage('flags.files.summary'),
exactlyOne: ['files', 'plan'],
aliases: ['sobjecttreefiles'],
deprecateAliases: true,
multiple: true,
delimiter: ',',
}),
plan: Flags.file({
char: 'p',
summary: messages.getMessage('flags.plan.summary'),
description: messages.getMessage('flags.plan.description'),
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.table({
data: results,
columns: [
{ key: 'refId', name: 'Reference ID' },
{ key: 'type', name: 'Type' },
{ key: 'id', name: 'ID' },
],
title: 'Import Results',
});
return results;
}
}