@mason-api/cli
Version:
CLI assistant for Mason builder
47 lines (39 loc) • 1.78 kB
JavaScript
;
var _yargs = _interopRequireDefault(require("yargs"));
var _babelPolyfill = _interopRequireDefault(require("babel-polyfill"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var yargs = _yargs.default // eslint-disable-line
.usage('Usage: $0 <command> [options]').example('$0 html 3030 4040 default').commandDir('commands').command('$0', 'default', function () {}, function (argv) {
setTimeout(function () {
// guide is a default command if `mason` is called without positional arguments
if (argv._.length === 0) {
yargs.exec("guide ".concat(process.argv.slice(2).join(' '))); // when arguments are provided but no command was matched, assume `generate` command
} else {
yargs.exec("generate ".concat(process.argv.slice(2).join(' ')));
}
}, 10);
}).option('verbose', {
alias: 'v',
describe: 'Output additional information'
}).option('api-key', {
alias: 'k',
describe: 'Key for authentication, can be set via $MASON_API_KEY'
});
global.yargs = yargs;
yargs.exec = function (input) {
yargs.parse(input, function (err, args, output) {
if (output) {
// Remove types (e.g. [string], [boolean]) from the output
output = output.replace('Positionals:', 'Arguments:');
output = output.replace(/\[\w+\]\n/g, '\n');
output = output.replace(/(?:\n\s+)?\[default:\s*(.*?)\]\n/g, '\n');
output = output.replace(/\[choices:\s*([\s\S]+?)\]\n/g, function (m, choices) {
return " (".concat(choices.replace(/"/g, '').replace(/\s+/g, ' '), ")\n");
});
output = output.replace(/\n\s*--version.*?\n/, '\n'); // Show the modified output
console.log(output);
}
});
};
yargs.exec(process.argv.slice(2));