diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-28 18:04:27 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-28 18:04:27 +0100 |
commit | de22e59896566ba9f680340e0e7d3744e539f4e4 (patch) | |
tree | c1d1689259cdfe438dba77ed07b3f6a91d642f3a /mongo-edu.js | |
parent | 9945c1051913e889bed8503dad04d5c8b1249cbd (diff) | |
download | mongo-edu-de22e59896566ba9f680340e0e7d3744e539f4e4.zip |
update
add presets
Diffstat (limited to 'mongo-edu.js')
-rw-r--r-- | mongo-edu.js | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/mongo-edu.js b/mongo-edu.js index fcee4ef..6876ce9 100644 --- a/mongo-edu.js +++ b/mongo-edu.js @@ -18,15 +18,17 @@ var pkg = require('./package'), colors = require('colors'), inquirer = require('inquirer'); +process.title = pkg.name; + exports.create = function start() { 'use strict'; - process.title = pkg.name; console.log('\n[ ' + pkg.name.toUpperCase() + ' ' + pkg.version + ' ]\n'); - var argv = yargs.argv, proxyDetails = {}, lookFor = ((!argv.h)? 'Videos' : 'Handouts'), isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/'; + var argv = yargs.argv, proxyDetails = {}, + lookFor = ((!argv.h)? 'Videos' : 'Handouts'), isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/'; if (argv.help) { return yargs.showHelp(); } @@ -34,9 +36,56 @@ exports.create = function start() { if (argv.d.substr(-1) !== slash) { argv.d += slash; } - validate.init(argv, function init(err, profile) { - if (err !== null) { throw err; } + if (argv.load) { + if (typeof argv.load === 'string') { + optArgs.load(argv.load, function load(err, data, status) { + if (err !== null || !status) { return console.log('i'.red + ' Preset: ' + argv.load.green + ' not found.'); } + argv = data; + initRun(); + }); + } else { + optArgs.get(function get(err, data) { + if (err !== null || !data.length) { return console.log('i'.magenta + ' No Presets Found.'); } + inquirer.prompt([{ type: 'list', name: 'preset', message: 'Select Preset To Load:', choices: data}], function prompt(answers) { + optArgs.load(answers.preset, function load(err, data, status) { + if (err !== null || !status) { return console.log('i'.red + ' Unable To Load Preset: ' + argv.load); } + argv = data; + initRun(); + }); + }); + }); + } + } + + function initRun() { + validate.init(argv, function init(err, profile) { + if (err !== null) { throw err; } + var savePrompt = [{ type: 'input', name: 'save', message: 'Missing [ --save ] Preset Name', default: '', validate: function(value) { + if (value !== '') { return true; } + return 'Please enter [ --save ] preset name'; + }}]; + + if (argv.save) { + if (typeof argv.save === 'string') { + optArgs.save(argv.save); + } else { + return inquirer.prompt(savePrompt, function savePrompt(answers) { + argv.save = answers.save; + optArgs.save(answers.save); + initAndConfigure(profile); + }); + } + } + + initAndConfigure(profile); + + }); + } + + if (!argv.load) { return initRun(); } + + function initAndConfigure(profile) { configure(argv, function conf(err) { if (err !== null) { throw err; } @@ -62,8 +111,7 @@ exports.create = function start() { }); }); - - }); + } function run(profile) { |