system_assignation/node_modules/repeating/cli.js

37 lines
674 B
JavaScript
Raw Normal View History

2022-03-24 09:22:39 -04:00
#!/usr/bin/env node
'use strict';
var pkg = require('./package.json');
var repeating = require('./');
var argv = process.argv.slice(2);
function help() {
console.log([
'',
' ' + pkg.description,
'',
' Usage',
' $ repeating <string> <count>',
'',
' Example',
' $ repeating \'unicorn \' 2',
' unicorn unicorn'
].join('\n'));
}
if (process.argv.indexOf('--help') !== -1) {
help();
return;
}
if (process.argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
if (!argv[1]) {
console.error('You have to define how many times to repeat the string.');
process.exit(1);
}
console.log(repeating(argv[0], Number(argv[1])));