zcatalyst-cli
Version:
Command Line Tool for CATALYST
52 lines (51 loc) • 2.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateActiveDC = exports.getActiveDCType = exports.getActiveDC = void 0;
const ansi_colors_1 = require("ansi-colors");
const config_store_1 = __importDefault(require("./config-store"));
const error_1 = __importDefault(require("./error"));
const constants_1 = require("./util_modules/constants");
const option_1 = require("./util_modules/option");
function getActiveDC() {
const envname = 'CATALYST_ACTIVE_DC';
if (process.env[envname] !== undefined) {
return process.env[envname];
}
let dcOption = (0, option_1.getGlobalOptionValue)('dc');
if (dcOption === undefined) {
const argv = process.argv.slice(2);
const dcIdx = argv.indexOf('--dc');
if (dcIdx !== -1) {
dcOption = argv[dcIdx + 1];
}
}
if (typeof dcOption === 'string') {
if (!Object.keys(constants_1.DC_TYPE).includes(dcOption)) {
throw new error_1.default('Provide DC in global option is not valid: ' + dcOption, {
exit: 1,
errorId: 'DC-1',
arg: [
ansi_colors_1.bold.red(dcOption),
(0, ansi_colors_1.bold)(Object.keys(constants_1.DC_TYPE)
.map((dc) => '* ' + dc)
.join('\n'))
]
});
}
return constants_1.DC_TYPE[dcOption].value;
}
return config_store_1.default.get('active_dc', constants_1.DEFAULT.dc);
}
exports.getActiveDC = getActiveDC;
function getActiveDCType() {
const activeDC = getActiveDC();
return Object.values(constants_1.DC_TYPE).find((type) => type.value === activeDC);
}
exports.getActiveDCType = getActiveDCType;
function updateActiveDC(dc) {
config_store_1.default.set('active_dc', dc);
}
exports.updateActiveDC = updateActiveDC;