devebot-cli
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -9,5 +9,7 @@ 'use strict'; | ||
var DevebotApi = require('devebot-api'); | ||
var appinfo = require('../lib/utils/appinfo.js'); | ||
var Config = require('../lib/utils/config.js'); | ||
var logger = require('../lib/utils/logger.js'); | ||
var TextUI = require('../lib/utils/textui.js'); | ||
var Myperf = require('../lib/utils/myperf.js'); | ||
@@ -17,4 +19,7 @@ module.exports = function(params) { | ||
var cfg = (new Config(params)).getConfig(); | ||
var cfgObj = new Config(params); | ||
var mpfObj = new Myperf(); | ||
var tui = new TextUI({ config: cfgObj, myperf: mpfObj }); | ||
var cfg = cfgObj.getConfig(); | ||
var devebot = new DevebotApi(lodash.extend(cfg, { | ||
@@ -29,7 +34,7 @@ logger: logger | ||
devebot.on('success', function(data) { | ||
displayResult(data.value || data.result); | ||
tui.displayResult(data.value || data.result); | ||
}); | ||
devebot.on('failure', function(data) { | ||
displayError(data.error); | ||
tui.displayError(data.error); | ||
}); | ||
@@ -45,6 +50,17 @@ | ||
var buildCmdline = function(devebot, clidef, callback) { | ||
var init = Promise.promisify(devebot.loadDefinition); | ||
init().then(function(clidef) { | ||
tui.displayCliHeader(clidef); | ||
return run(devebot, clidef).then(function() { | ||
tui.displayCliFooter(clidef); | ||
}); | ||
}).catch(function(exception) { | ||
tui.displayException(exception); | ||
}); | ||
}; | ||
var run = function(devebot, clidef) { | ||
return Promise.promisify(function(callback) { | ||
clidef = clidef || {}; | ||
logger.trace(' * build commandline with definition: %s', JSON.stringify(clidef, null, 2)); | ||
logger.trace(' * cli definition: %s', JSON.stringify(clidef, null, 2)); | ||
@@ -81,41 +97,3 @@ var commands = clidef.commands || []; | ||
program.parse(process.argv); | ||
}; | ||
var displayResult = function(result) { | ||
console.log(''); | ||
process.stdout.write(util.format('Command result: %s\n', JSON.stringify(result, null, 2))); | ||
}; | ||
var displayError = function(error) { | ||
console.log(''); | ||
if (lodash.isObject(error)) { | ||
if (error.name == 'restapi_request_error' || error.name == 'restapi_invalid_status') { | ||
[ | ||
"Fatal error: Unable to find devebot service.", | ||
"", | ||
"If you're seeing this message, either the devebot service hasn't been installed,", | ||
"or it is running incorrectly.", | ||
].forEach(function(str) { process.stderr.write(util.format('%s\n', str)); }); | ||
} else { | ||
process.stderr.write(util.format('Command error: %s\n', JSON.stringify(error, null, 2))); | ||
} | ||
} else { | ||
process.stderr.write(util.format('Unknown error: %s\n', error)); | ||
} | ||
}; | ||
Promise.resolve().then(function() { | ||
return Promise.promisify(devebot.loadDefinition)(); | ||
}).then(function(clidef) { | ||
return Promise.resolve().then(function() { | ||
appinfo.displayCliHeader(clidef); | ||
return Promise.promisify(buildCmdline)(devebot, clidef); | ||
}).then(function() { | ||
appinfo.displayCliFooter(clidef); | ||
return Promise.resolve(); | ||
}); | ||
}).catch(function(exception) { | ||
appinfo.displayCliFooter(); | ||
}); | ||
})(); | ||
}; |
@@ -6,31 +6,12 @@ 'use strict'; | ||
// Project metadata. | ||
var pkg = JSON.parse(fs.readFileSync(__dirname + '/../../package.json', 'utf8')); | ||
var pkgAppinfo = lodash.pick(pkg, ['version', 'name', 'description', 'homepage', 'author', 'license']); | ||
// Program package information | ||
var pkgProgram = JSON.parse(fs.readFileSync('package.json', 'utf8')); | ||
var pkgDevebot = JSON.parse(fs.readFileSync(__dirname + '/../../package.json', 'utf8')); | ||
var appinfo = {}; | ||
var appinfo = lodash.pick(pkgProgram || pkgDevebot, | ||
['version', 'name', 'description', 'homepage', 'author', 'license']); | ||
// Commandline user-agent | ||
appinfo.useragent = [pkg.name, '/', pkg.version].join(''); | ||
appinfo.useragent = [appinfo.name, '/', appinfo.version].join(''); | ||
// Commandline header. | ||
appinfo.displayCliHeader = function(clidef) { | ||
clidef = clidef || {}; | ||
var info = clidef.appinfo || pkgAppinfo; | ||
console.log('%s: %s (v%s)', info.name, info.description, info.version); | ||
}; | ||
// Commandline footer. | ||
appinfo.displayCliFooter = function(clidef) { | ||
clidef = clidef || {}; | ||
var info = clidef.appinfo || pkgAppinfo; | ||
[ | ||
"", | ||
"------------------------------------------------------------------------------------", | ||
"For more information about installing and configuring devebot, please see the guide:", | ||
info.homepage || pkgAppinfo.homepage, | ||
"", | ||
].forEach(function(str) { console.log(str); }); | ||
}; | ||
module.exports = appinfo; | ||
module.exports = appinfo; |
@@ -16,2 +16,3 @@ 'use strict'; | ||
var defaultConfig = params.defaultConfig || { | ||
protocol: 'http', | ||
host: '0.0.0.0', | ||
@@ -55,2 +56,6 @@ port: 17779, | ||
self.getContext = function() { | ||
return configContext; | ||
}; | ||
self.getConfig = function() { | ||
@@ -57,0 +62,0 @@ if (lodash.isString(configContext) && !lodash.isEmpty(configContext)) { |
{ | ||
"name": "devebot-cli", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "command line interface", | ||
@@ -5,0 +5,0 @@ "main": "lib/client.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10723
10
282
0