generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.ts
68 lines (60 loc) · 2.41 KB
/
get.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
/*
* 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 { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigAggregator, Messages } from '@salesforce/core';
import {
CONFIG_HELP_SECTION,
calculateSuggestion,
buildFailureMsg,
buildSuccessMsg,
output,
ConfigResponses,
} from '../../config.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.get');
export class Get extends SfCommand<ConfigResponses> {
public static readonly description = messages.getMessage('description');
public static readonly summary = messages.getMessage('summary');
public static readonly examples = messages.getMessages('examples');
public static readonly aliases = ['force:config:get'];
public static readonly deprecateAliases = true;
public static readonly strict = false;
public static readonly flags = {
loglevel,
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};
public static configurationVariablesSection = CONFIG_HELP_SECTION;
public async run(): Promise<ConfigResponses> {
const { argv, flags } = await this.parse(Get);
const responses: ConfigResponses = [];
if (!argv || argv.length === 0) {
throw messages.createError('error.NoConfigKeysFound');
}
const aggregator = await ConfigAggregator.create();
for (const configName of argv as string[]) {
try {
responses.push(buildSuccessMsg(aggregator.getInfo(configName)));
} catch (err) {
if (err instanceof Error && err.name.includes('UnknownConfigKeyError') && !this.jsonEnabled()) {
const suggestion = calculateSuggestion(configName);
// eslint-disable-next-line no-await-in-loop
const answer = await this.confirm({ message: messages.getMessage('didYouMean', [suggestion]) });
if (answer) {
responses.push(buildSuccessMsg(aggregator.getInfo(suggestion, false)));
}
} else {
responses.push(buildFailureMsg(configName, err));
process.exitCode = 1;
}
}
}
output(new Ux({ jsonEnabled: this.jsonEnabled() }), responses, 'get', flags.verbose);
return responses;
}
}