rainbows
Version:
Outputs a random number (`1 <= n <= 1000`) of 🌈's when you execute the program. (Pretty much useless.)
27 lines (26 loc) • 1.08 kB
JavaScript
;
const command_1 = require("@oclif/command");
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
// The maximum is exclusive and the minimum is inclusive
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
const MAX_NUM_RAINBOWS = 1000;
class Rainbows extends command_1.Command {
async run() {
const { args } = this.parse(Rainbows);
const numRainbows = Math.min(Number(args.numRainbows) || getRandomInt(1, MAX_NUM_RAINBOWS + 1), MAX_NUM_RAINBOWS);
this.log(`Here ${numRainbows > 1 ? 'are' : 'is'} ${numRainbows} rainbow${numRainbows > 1 ? 's' : ''} for you!`);
this.log('🌈'.repeat(numRainbows));
}
}
Rainbows.description = 'Outputs rainbows';
Rainbows.flags = {
// add --version flag to show CLI version
version: command_1.flags.version({ char: 'v' }),
help: command_1.flags.help({ char: 'h' }),
};
Rainbows.args = [{ name: 'numRainbows' }];
module.exports = Rainbows;