@codification/cutwater-build-aws
Version:
Tasks for working with AWS.
62 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CliUtils = void 0;
const cutwater_build_node_1 = require("@codification/cutwater-build-node");
class CliUtils {
static prepareArgs(config, cmdOpts) {
const cmd = CliUtils.preparedCommand(cmdOpts === null || cmdOpts === void 0 ? void 0 : cmdOpts.command, cmdOpts === null || cmdOpts === void 0 ? void 0 : cmdOpts.subCommand);
const opts = CliUtils.preparedOptions(config, cmdOpts === null || cmdOpts === void 0 ? void 0 : cmdOpts.filteredParams);
const params = CliUtils.preparedParameters(config, cmdOpts === null || cmdOpts === void 0 ? void 0 : cmdOpts.filteredParams);
const args = config.args ? ' ' + config.args.join(' ') : '';
return `${cmd}${opts}${params}${args}`;
}
static preparedCommand(command = '', subCommand = '') {
return !!command ? `${command}${!!subCommand ? ' ' + subCommand : ''} ` : '';
}
static preparedOptions(config, filteredParams) {
return !!config.options ? CliUtils.toArgString(config.options, filteredParams) : '';
}
static toArgString(args, filteredParams = []) {
const argArray = Object.keys(args)
.filter((property) => !filteredParams.includes(property))
.map((property) => {
const value = args[property];
const arg = cutwater_build_node_1.TextUtils.convertPropertyNameToArg(property);
if (typeof value === 'string') {
return `${arg} "${value}"`;
}
else if (typeof value === 'boolean' && !!value) {
return arg;
}
else if (typeof value === 'number') {
return `${arg} ${value}`;
}
else if (Array.isArray(value)) {
return `${arg} ${CliUtils.toParameterList(value)}`;
}
else if (typeof value === 'object') {
return `${arg} '${JSON.stringify(value)}'`;
}
return '';
});
return ` ${argArray.join(' ')}`;
}
static toParameterList(arg) {
return arg
.map((value) => {
if (typeof value === 'string') {
return `"${value}"`;
}
else if (typeof value === 'number') {
return value;
}
return '';
})
.join(' ');
}
static preparedParameters(config, filteredParams) {
return !!config.parameters ? CliUtils.toArgString(config.parameters, filteredParams) : '';
}
}
exports.CliUtils = CliUtils;
//# sourceMappingURL=CliUtils.js.map