@adpt/cli
Version:
AdaptJS command line interface
78 lines • 3.09 kB
JavaScript
;
/*
* Copyright 2020 Unbounded Systems, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@adpt/utils");
const base_1 = require("../../base");
const config_1 = require("../../config");
class ConfigSetCommand extends base_1.AdaptBase {
async run() {
const { args } = this.parse(ConfigSetCommand);
const { name, value } = args;
let toStore;
const prop = config_1.lookupConfigProperty(name);
if (!prop) {
throw new utils_1.UserError(`Invalid configuration setting name '${name}'. ` +
`Expected one of: ${config_1.userConfigProps.join(", ")}`);
}
try {
const item = config_1.parseConfigItemString(prop, value);
toStore = item.store;
}
catch (err) {
const expected = err &&
err.name === config_1.SchemaValidationError.name &&
err.expectedType;
if (!expected)
throw err;
throw new utils_1.UserError(`Invalid value: '${value}' is not type ${expected}`);
}
const { userConfigFile } = await config_1.config();
const writer = await utils_1.createJson5Writer(userConfigFile, { mustExist: false });
const orig = writer.value === undefined ? {} : writer.value;
if (orig == null || !utils_1.isObject(orig) || Array.isArray(orig)) {
return config_1.throwConfigFileError(userConfigFile, new Error(`Does not contain a single object in ` +
`JSON/JSON5 format (actual type=${typeof orig})`));
}
try {
await writer.update(Object.assign({}, orig, { [prop]: toStore }));
}
catch (err) {
return config_1.throwConfigFileError(userConfigFile, err, "write");
}
}
}
ConfigSetCommand.description = "Modify Adapt configuration settings";
ConfigSetCommand.examples = [
`Change the upgrade check notification to use the "next" channel:
$ adapt config:set upgradeChannel next`,
];
ConfigSetCommand.flags = Object.assign({}, base_1.AdaptBase.flags);
ConfigSetCommand.args = [
{
name: "name",
required: true,
description: `The name of the configuration item to be modified\n` +
`(not case-sensitive)`,
},
{
name: "value",
required: true,
description: `The value to assign to the configuration item`,
}
];
exports.default = ConfigSetCommand;
//# sourceMappingURL=set.js.map