summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprzemyslawpluta <przemekpluta@hotmail.com>2014-09-29 23:13:38 +0100
committerprzemyslawpluta <przemekpluta@hotmail.com>2014-09-29 23:13:38 +0100
commited08b6cc288cdb5069f212b0df5708b074e4fc10 (patch)
treeda3c35524ca0d81df48c6ef5aff7b2f0099a5e47
parentd3fdaecee4893bbd98ad22beb9323bdc2e638b47 (diff)
downloadmongo-edu-ed08b6cc288cdb5069f212b0df5708b074e4fc10.zip
update
add presets list cleaup version bump
-rw-r--r--lib/options.js73
-rw-r--r--package.json5
2 files changed, 76 insertions, 2 deletions
diff --git a/lib/options.js b/lib/options.js
index 17fedc8..b549328 100644
--- a/lib/options.js
+++ b/lib/options.js
@@ -10,6 +10,7 @@ var fs = require('fs'),
path = require('path'),
_ = require('lodash'),
inquirer = require('inquirer'),
+ Table = require('easy-table'),
prompts = require('./prompts'),
yargs = require('yargs')
.usage('Usage: $0 [options]')
@@ -110,6 +111,75 @@ function promptAsk(data, argv, initRun) {
});
}
+function showSign(item, rev) {
+
+ 'use strict';
+ if (!item) { return ''; }
+ if (typeof item !== 'boolean') { return item; }
+ if (!rev) { return (item) ? ' x' : ''; }
+ return (item) ? '' : ' x';
+}
+
+function checkIfFilled(item, name, target, clear) {
+
+ 'use strict';
+
+ var i;
+ for (i = 0; i < item.length; i++) {
+ if (item[i][name] !== '') { clear.push(target); break; }
+ }
+}
+
+function showPresets(argv, initRun, checkIfLoad) {
+
+ 'use strict';
+
+ readFromPath(function read(err, data) {
+ if (err !== null) { return console.log('i'.red + ' No Presets Found.'); }
+ var items = _.values(data), presets = _.keys(data), count = 0, t = new Table, i, names = [], clear = [];
+
+ items.forEach(function each(item) {
+ t.cell('Preset', presets[count]);
+ t.cell('User', item.u);
+ t.cell('Wiki List', showSign(item.cw, true));
+ t.cell('Courseware', showSign(item.cw));
+ t.cell('HQ Video', showSign(item.hq));
+ t.cell('CC', showSign(item.cc));
+ t.cell('Seq Order', showSign(item.co));
+ t.cell('Dump List', showSign(item.cwd));
+ t.cell('Handouts', showSign(item.h));
+ t.cell('UnZip', showSign(item.uz));
+ t.cell('Debug', showSign(item.verbose));
+ t.cell('PY NCC', showSign(item.ncc));
+ t.cell('PY', showSign(item.py));
+ t.cell('Proxy', showSign(item.proxy));
+ t.cell('Proxy Test', showSign(item.test));
+ if (count === 0) { names = _.keys(t._row); }
+ count = count + 1;
+ t.newRow();
+ });
+
+ for (i = 0; i < names.length; i++) {
+ checkIfFilled(t.rows, names[i], i, clear);
+ }
+
+ clear = clear.map(function map(item) { return names[item]; });
+
+ for (i = 0; i < t.rows.length; i++) {
+ t.rows[i] = _.pick(t.rows[i], clear);
+ }
+
+ t.columns = _.pick(t.columns, clear);
+
+ console.log(t.toString());
+
+ argv.load = true;
+
+ checkIfLoad(_.omit(argv, 'save'), initRun);
+
+ });
+}
+
module.exports = (function init() {
'use strict';
@@ -119,6 +189,7 @@ module.exports = (function init() {
checkIfLoad: function checkIfLoad(argv, initRun) {
if (!argv.load) { return initRun(argv); }
if (typeof argv.load === 'string') {
+ if (argv.load === '..') { return showPresets(argv, initRun, checkIfLoad); }
loadOptions(argv.load, function load(err, data, status) {
if (err !== null || !status) { return console.log('i'.red + ' Preset: ' + argv.load.green + ' not found.'); }
initRun(data);
@@ -133,7 +204,7 @@ module.exports = (function init() {
checkIfSave: function checkIfSave(argv, initAndConfigure, profile) {
if (argv.save) {
if (typeof argv.save === 'string') {
- saveOptions(argv.save);
+ if (argv.save !== '..') { saveOptions(argv.save); }
} else {
return inquirer.prompt(prompts.savePreset, function savePreset(answers) {
argv.save = answers.save;
diff --git a/package.json b/package.json
index 35720d2..ba402e7 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.1.50",
+ "version": "0.1.60",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
@@ -32,12 +32,15 @@
"dependencies": {
"cheerio": "~0.17.0",
"colors": "~0.6.2",
+ "easy-table": "~0.3.0",
"filesize": "~2.0.3",
"glob": "~4.0.6",
"inquirer": "~0.8.0",
+ "install": "^0.1.7",
"lodash": "~2.4.1",
"mkdirp": "~0.5.0",
"mv": "~2.0.3",
+ "npm": "^2.0.2",
"progress": "~1.1.8",
"request": "~2.42.0",
"request-progress": "~0.3.1",