don667
Version:
DONNN! Based on Cowsay (https://github.com/piuccio/cowsay)
61 lines (53 loc) • 1.54 kB
JavaScript
const yargs = require('yargs');
const fs = require('fs');
const path = require('path');
const argv = yargs.argv;
function getList() {
console.log('Available faces:\n');
// Получаем все файлы в папке faces, выводим их в консоль, убирая путь к ним и расширение .txt
getFiles(`${__dirname}/faces`).forEach(file => console.log(path.basename(file, path.extname(file))));
}
function getHelp() {
// TODO:
// -a, --add\t\tAdd a new face to the list. An image file or a text file must be provided.
// -m, --monochrome\tForce monochrome mode
console.log(`Usage: don [options] [arguments]
Options:
-f, --face\t\tShow a specific face
-h, --help\t\tShow this help
-l, --list\t\tList all available faces
-r, --random\t\tShow a random face`);
}
switch (true) {
// case argv.a || argv.add:
// break;
case argv.h || argv.help:
getHelp();
break;
case argv.l || argv.list:
getList();
break;
// case argv.m || argv.monochrome:
// break;
default:
say();
break;
}
function getFiles(dir, files_) {
files_ = files_ || [];
var files = fs.readdirSync(dir);
for (var i in files) {
var name = dir + '/' + files[i];
if (fs.statSync(name).isDirectory()) {
getFiles(name, files_);
} else {
files_.push(name);
}
}
return files_;
}
function say() {
const module = require('./index.js');
console.log(module.say(argv));
}