generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpermsetlicense.ts
64 lines (59 loc) · 2.12 KB
/
permsetlicense.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 { Messages } from '@salesforce/core';
import { arrayWithDeprecation, Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { ensureArray } from '@salesforce/kit';
import {
aggregate,
assignPSL,
print,
PSLResult,
resultsToExitCode,
} from '../../../baseCommands/user/permsetlicense/assign.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-user', 'permsetlicense.assign');
export class AssignPermSetLicenseCommand extends SfCommand<PSLResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly flags = {
name: Flags.string({
char: 'n',
summary: messages.getMessage('flags.name.summary'),
required: true,
aliases: ['perm-set-license', 'psl'],
multiple: true,
}),
'on-behalf-of': arrayWithDeprecation({
char: 'b',
summary: messages.getMessage('flags.onBehalfOf.summary'),
aliases: ['onbehalfof'],
deprecateAliases: true,
}),
'target-org': Flags.requiredOrg({ summary: messages.getMessage('flags.target-org.summary'), required: true }),
'api-version': Flags.orgApiVersion(),
};
public async run(): Promise<PSLResult> {
const { flags } = await this.parse(AssignPermSetLicenseCommand);
const result = aggregate(
await Promise.all(
flags.name.map((pslName) =>
assignPSL({
conn: flags['target-org'].getConnection(flags['api-version']),
pslName,
usernamesOrAliases: ensureArray(flags['on-behalf-of'] ?? flags['target-org'].getUsername()),
})
)
)
);
process.exitCode = resultsToExitCode(result);
if (!this.jsonEnabled()) {
print(result);
}
return result;
}
}