From ed08b6cc288cdb5069f212b0df5708b074e4fc10 Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Mon, 29 Sep 2014 23:13:38 +0100 Subject: update add presets list cleaup version bump --- lib/options.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'lib/options.js') 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; -- cgit v1.2.3