diff --git a/commands/import.js b/commands/import.js index 38bd338..07c4b99 100644 --- a/commands/import.js +++ b/commands/import.js @@ -13,6 +13,8 @@ var JSZip = require('jszip'); var Command = require('ronin').Command; var bbrest, jxon, cfg; +var unknownImportError = 'Unknown import message.'; +var defaultTimeout = 10000; module.exports = Command.extend({ help: function () { @@ -30,6 +32,8 @@ module.exports = Command.extend({ r += ' -u, --username \t\t' + d('admin') + '\t\tUsername.\n'; r += ' -w, --password \t\t' + d('admin') + '\t\tPassword.\n'; r += ' -p, --portal \t\t\t\tName of the portal on the server to target.\n'; + r += ' -v, --verbose \t\t\t\tPrints out raw error.\n'; + r += ' -o, --timeout \t\t\t\tMax number of seconds that process can take.\n'; r += '\n ' + title('Examples') + ':\n\n'; r += ' bb import --target myPortal.xml\t\t\tImports portal from myPortal.xml\n'; r += ' bb import --target chunked\t\t\tImports bb export chunked portal from chunked dir\n'; @@ -40,11 +44,17 @@ module.exports = Command.extend({ target: {type: 'string', alias: 't'}, dashboard: {type: 'boolean', alias: 'd'}, save: {type: 'string', alias: 's'}, - portal: {type: 'string', alias: 'p'} + portal: {type: 'string', alias: 'p'}, + verbose: {type: 'boolean', alias: 'v'}, + timeout: {type: 'string', alias: 'o'} }), run: function () { + // if timeout < 100 ? multiply by 1000 : use as is. + var timeout = +this.options.timeout > 0 && +this.options.timeout || defaultTimeout; + this.options.timeout = timeout > 100 && timeout || timeout * 1000; + util.spin.message('Loading...'); util.spin.start(); return config.getCommon(this.options) @@ -70,11 +80,17 @@ module.exports = Command.extend({ throw new Error('Target is not directory or file.'); }) .then(function(bbr) { - if (bbr.error) { - var emsg = jxon.stringToJs(bbr.body); - emsg = emsg.errorMessage || emsg.importErrorMessage || {message: 'Unknown import message.'}; - throw new Error(emsg.message); - } else ok(bbr); + if (bbr.error === false) { + ok(bbr); + } else { + if (cfg.verbose === true) { + throw new Error(formattor(bbr, {method: 'json'})); + } else { + var emsg = jxon.stringToJs(bbr.body); + emsg = emsg.errorMessage || emsg.importErrorMessage || {message: unknownImportError}; + throw new Error(emsg.message); + } + } }) .catch(function(err) { if (err.code === 'ENOENT') return error(new Error('Target does not exist.')); @@ -192,6 +208,7 @@ function importDashboard() { username: bbrc.username, password: bbrc.password }, + timeout: bbrc.timeout, headers: { Pragma: 'no-cache', 'Accept-Encoding': 'gzip, deflate', diff --git a/lib/config.js b/lib/config.js index d6709f8..bc31360 100644 --- a/lib/config.js +++ b/lib/config.js @@ -88,7 +88,7 @@ exports.getCommon = function (cliConfig) { bbrest = new BBRest(); // merge .bbrc properties - var cnames = ['scheme', 'host', 'port', 'context', 'username', 'password', 'portal']; + var cnames = ['scheme', 'host', 'port', 'context', 'username', 'password', 'portal', 'timeout']; _.merge(bbrest.config, _.pick(config.bbrc, cnames)); _.merge(bbrest.config, _.pick(config.cli, cnames));