UNPKG

kangaroo-cli

Version:
26 lines (21 loc) 690 B
const chalk = require('chalk'); exports.error = chalk.bold.red; exports.warning = chalk.keyword('orange'); exports.upperFirst = function (name) { return name.charAt(0).toUpperCase() + name.slice(1); }; exports.cleanArgs = function (cmd) { const args = {}; cmd.options.forEach((o) => { const key = camelize(o.long.replace(/^--/, '')); // if an option is not present and Command has a method with the same name // it should not be copied if (typeof cmd[key] !== 'function' && typeof cmd[key] !== 'undefined') { args[key] = cmd[key]; } }); return args; }; function camelize(str) { return str.replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : '')); }