pkgcloud-cli
Advanced tools
Comparing version 0.2.6 to 0.3.0
@@ -5,2 +5,3 @@ var cloud = require('pkgcloud'); | ||
var dateformat = require('dateformat'); | ||
var prettyjson = require('prettyjson'); | ||
@@ -23,3 +24,2 @@ var exports = {}; | ||
var configFile = file; | ||
var stats = fs.statSync(configFile); | ||
var config = JSON.parse(fs.readFileSync(configFile).toString()); | ||
@@ -38,2 +38,19 @@ | ||
var assertSectionInConfigFile = function (config, sectionName) { | ||
if (!config[sectionName]) { | ||
console.error("The pkgcloud-cli.json section is missing a ["+ | ||
sectionName + "] section"); | ||
process.exit(0); | ||
} | ||
}; | ||
var globalErrorHandler = function(message, data){ | ||
var prettyJson = prettyjson.render(data); | ||
console.log("\n"); | ||
console.log(message.red); | ||
console.log(prettyJson); | ||
console.log("\n"); | ||
process.exit(1); | ||
}; | ||
exports.init = function(config, type, callback) { | ||
@@ -44,2 +61,3 @@ if (!config) { | ||
config = loadConfig(config); | ||
assertSectionInConfigFile(config, type.toLowerCase()); | ||
if (type === CLIENT_TYPES.compute) { | ||
@@ -54,2 +72,7 @@ client = cloud.compute.createClient(config.compute[0]); | ||
} | ||
if(client) { | ||
client.on("log::error", globalErrorHandler); | ||
} | ||
return callback(null, client); | ||
@@ -82,2 +105,2 @@ }; | ||
module.exports = exports; | ||
module.exports = exports; |
{ | ||
"name": "pkgcloud-cli", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "CLI for pkgcloud", | ||
@@ -53,11 +53,12 @@ "scripts": { | ||
"dependencies": { | ||
"commander": "~2.0.0", | ||
"commander": "~2.2.0", | ||
"pkgcloud": "~0.8.17", | ||
"nconf": "~0.6.7", | ||
"path": "~0.4.9", | ||
"cli-table": "~0.2.0", | ||
"cli-table": "~0.3.0", | ||
"dateformat": "~1.0.6-1.2.3", | ||
"underscore": "~1.5.2", | ||
"pkginfo": "~0.3.0" | ||
"underscore": "~1.6.0", | ||
"pkginfo": "~0.3.0", | ||
"prettyjson": "~1.0.0" | ||
} | ||
} |
39943
87
9
+ Addedprettyjson@~1.0.0
+ Addedcli-table@0.3.11(transitive)
+ Addedcolors@0.6.21.0.3(transitive)
+ Addedcommander@2.2.0(transitive)
+ Addedminimist@0.0.8(transitive)
+ Addedprettyjson@1.0.0(transitive)
+ Addedunderscore@1.6.0(transitive)
- Removedcli-table@0.2.0(transitive)
- Removedcolors@0.3.0(transitive)
- Removedcommander@2.0.0(transitive)
- Removedunderscore@1.5.2(transitive)
Updatedcli-table@~0.3.0
Updatedcommander@~2.2.0
Updatedunderscore@~1.6.0