@salesforce/plugin-settings
Version:
configure the Salesforce CLI
56 lines • 2.51 kB
JavaScript
/*
* 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, } from '../../config.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.get');
export class Get extends SfCommand {
static description = messages.getMessage('description');
static summary = messages.getMessage('summary');
static examples = messages.getMessages('examples');
static aliases = ['force:config:get'];
static deprecateAliases = true;
static strict = false;
static flags = {
loglevel,
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};
static configurationVariablesSection = CONFIG_HELP_SECTION;
async run() {
const { argv, flags } = await this.parse(Get);
const responses = [];
if (!argv || argv.length === 0) {
throw messages.createError('error.NoConfigKeysFound');
}
const aggregator = await ConfigAggregator.create();
for (const configName of argv) {
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;
}
}
//# sourceMappingURL=get.js.map