diff options
author | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-28 18:36:08 +0100 |
---|---|---|
committer | przemyslawpluta <przemekpluta@hotmail.com> | 2014-09-28 18:36:08 +0100 |
commit | 75245d62fdd7230ac3bdb634f26ad0da8826f61f (patch) | |
tree | d9156924b6d80fdbf024652ae4184fd5fd37bcfe | |
parent | 50b4cf93765ad4a74672baa12f8d59772356aad9 (diff) | |
download | mongo-edu-75245d62fdd7230ac3bdb634f26ad0da8826f61f.zip |
cleanup
-rw-r--r-- | lib/initialize.js | 10 | ||||
-rw-r--r-- | lib/prompts.js | 44 | ||||
-rw-r--r-- | lib/validate.js | 14 | ||||
-rw-r--r-- | mongo-edu.js | 15 |
4 files changed, 54 insertions, 29 deletions
diff --git a/lib/initialize.js b/lib/initialize.js index cbb2d99..a3c6834 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -8,6 +8,7 @@ var mdbvideos = require('./login'), videoHandler = require('./videos'), + prompts = require('./prompts'), colors = require('colors'), inquirer = require('inquirer'); @@ -19,14 +20,7 @@ module.exports = function run(profile, argv) { inquirer.prompt(profile, function prompt(answers) { - var list = [{ type: 'list', name: 'url', message: '', choices: [] }], classes = list, - - check = [{ type: 'checkbox', message: '', name: 'videos', choices: [], - validate: function validate(answer) { - if ( answer.length < 1 ) { return 'You must choose at least one option.'; } - return true; - } - }]; + var list = prompts.list, classes = list, check = prompts.check; mdbvideos.init(answers, argv, function get(err, data) { if (err !== null) { throw err; } diff --git a/lib/prompts.js b/lib/prompts.js new file mode 100644 index 0000000..0af81e8 --- /dev/null +++ b/lib/prompts.js @@ -0,0 +1,44 @@ +/* + * mongo-edu + * + * Copyright (c) 2014 Przemyslaw Pluta + * Licensed under the MIT license. + * https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE + */ + +module.exports = (function build() { + + 'use strict'; + + return { + savePrompt: [{ type: 'input', name: 'save', message: 'Missing [ --save ] Preset Name', default: '', validate: function(value) { + if (value !== '') { return true; } + return 'Please enter [ --save ] preset name'; + }}], + + loadPreset: function loadPreset(data) { + return [{ type: 'list', name: 'preset', message: 'Select Preset To Load:', choices: data}]; + }, + + list: [{ type: 'list', name: 'url', message: '', choices: [] }], + + check: [{ type: 'checkbox', message: '', name: 'videos', choices: [], + validate: function validate(answer) { + if ( answer.length < 1 ) { return 'You must choose at least one option.'; } + return true; + } + }], + + profile: [ + { type: 'input', name: 'user', message: 'MongoDB Uni User Name', default: '', validate: function(value) { + if (value !== '') { return true; } + return 'Please enter your MongoDB Uni user name - email address'; + }}, + { type: 'password', message: 'MongoDB Uni Password', name: 'password', validate: function(value) { + if (value !== '') { return true; } + return 'Please enter your MongoDB Uni password'; + }} + ] + }; + +}()); diff --git a/lib/validate.js b/lib/validate.js index c6909d6..d0b5e9e 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -6,22 +6,14 @@ * https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE */ -var mkdirp = require('mkdirp'); +var mkdirp = require('mkdirp'), + prompts = require('./prompts'); module.exports.init = function init(opt, callback) { 'use strict'; - var profile = [ - { type: 'input', name: 'user', message: 'MongoDB Uni User Name', default: '', validate: function(value) { - if (value !== '') { return true; } - return 'Please enter your MongoDB Uni user name - email address'; - }}, - { type: 'password', message: 'MongoDB Uni Password', name: 'password', validate: function(value) { - if (value !== '') { return true; } - return 'Please enter your MongoDB Uni password'; - }} - ]; + var profile = prompts.profile; if (opt.u !== '') { profile[0].default = opt.u; } diff --git a/mongo-edu.js b/mongo-edu.js index ed6dfd1..78cae7b 100644 --- a/mongo-edu.js +++ b/mongo-edu.js @@ -13,6 +13,7 @@ var pkg = require('./package'), validate = require('./lib/validate'), videoHandler = require('./lib/videos'), initialize = require('./lib/initialize'), + prompts = require('./lib/prompts'), yargs = optArgs.build(), url = require('url'), path = require('path'), @@ -27,8 +28,7 @@ exports.create = function start() { console.log('\n[ ' + pkg.name.toUpperCase() + ' ' + pkg.version + ' ]\n'); - var argv = yargs.argv, proxyDetails = {}, - isWin = /^win/.test(process.platform), slash = (isWin) ? '\\' : '/'; + var argv = yargs.argv, slash = (/^win/.test(process.platform)) ? '\\' : '/'; if (argv.help) { return yargs.showHelp(); } @@ -46,7 +46,7 @@ exports.create = function start() { } 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) { + inquirer.prompt(prompts.loadPreset(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; @@ -61,16 +61,11 @@ exports.create = function start() { 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) { + return inquirer.prompt(prompts.savePrompt, function savePrompt(answers) { argv.save = answers.save; optArgs.save(answers.save); initAndConfigure(profile); @@ -91,7 +86,7 @@ exports.create = function start() { if (!argv.proxy || argv.h) { return initialize(profile, argv); } - proxyDetails = url.parse(argv.proxy); + var proxyDetails = url.parse(argv.proxy); console.log('i'.magenta + ' Proxy Host: '.bold + proxyDetails.hostname.cyan + ' Port: '.bold + proxyDetails.port.cyan + ' Protocol: '.bold + proxyDetails.protocol.replace(':', '').toUpperCase().cyan); |