@semo/cli
Version:
A command line tools dispatcher
63 lines • 2.93 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.desc = exports.command = exports.plugin = exports.disabled = void 0;
const core_1 = require("@semo/core");
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const yaml_1 = __importDefault(require("yaml"));
exports.disabled = false; // Set to true to disable this command temporarily
exports.plugin = 'semo';
exports.command = 'get <configKey>';
exports.desc = 'Get configs by key';
// export const aliases = ''
// export const middleware = (argv) => {}
const builder = function (yargs) {
// yargs.option('option', { default, describe, alias })
// yargs.commandDir('get')
};
exports.builder = builder;
const handler = function (argv) {
return __awaiter(this, void 0, void 0, function* () {
if (core_1.Utils._.isString(argv.configKey)) {
argv.configKey = argv.configKey.split('.');
}
const scriptName = argv.scriptName || 'semo';
let configPath;
if (argv.global) {
configPath = process.env.HOME
? path_1.default.resolve(process.env.HOME, '.' + scriptName, '.' + scriptName + 'rc.yml')
: '';
}
else {
configPath = path_1.default.resolve(process.cwd(), '.' + scriptName + 'rc.yml');
}
if (!configPath || !fs_extra_1.default.existsSync(configPath)) {
core_1.Utils.error('Config file not found.');
return;
}
const rcFile = fs_extra_1.default.readFileSync(configPath, 'utf8');
const config = yaml_1.default.parse(rcFile);
const found = core_1.Utils._.get(config, argv.configKey);
if (found) {
const tmpConfig = core_1.Utils._.set({}, argv.configKey, found);
console.log(yaml_1.default.stringify(tmpConfig));
}
else {
core_1.Utils.warn('Config not found by key: ' + argv.configKey.join('.'));
}
});
};
exports.handler = handler;
//# sourceMappingURL=get.js.map