From 7b61c5e38459d9672b7024814c1e4df832d0c693 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Tue, 1 May 2012 16:43:56 -0700 Subject: [PATCH] formatting --- lib/cli/cli.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 32371778b..7d3bbb6bc 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -33,7 +33,7 @@ var istty1 = tty.isatty(1); if (!process.env.AZURE_DEBUG || process.env.AZURE_DEBUG !== '1') { process.on('uncaughtException', function (err) { clearProgress(); - + var loggedFullError = false; if (err.message) { log.error(err.message); @@ -53,18 +53,17 @@ if (!process.env.AZURE_DEBUG || process.env.AZURE_DEBUG !== '1') { } cli.exit('error', null, 1); -}); + }); } - /////////////////////////// // prepare output logger // use cli output settings by default log.cli(); -log.format = function(options) { - var transport = log['default'].transports.console; +log.format = function (options) { + var transport = log['default'].transports.console; if (arguments.length === 0) { return { json: transport.json, @@ -73,20 +72,23 @@ log.format = function(options) { logo: log.format.logo }; } - + if (options.json) { log.padLevels = false; log.stripColors = true; transport.json = true; transport.terse = true; } + if (options.terse) { log.padLevels = false; transport.terse = true; } + if (options.level) { transport.level = options.level; } + if (options.logo) { log.format.logo = options.logo; } @@ -98,12 +100,13 @@ log.json = function (level, data) { data = level; level = 'data'; } + if (log.format().json) { log.log(level, typeof data, data); } else { var lines = eyes.inspect(data, level, { stream: false }); lines.split('\n').forEach(function (line) { - // eyes all is "cyan" by default, so this property accessor will + // eyes all is "cyan" by default, so this property accessor will // fix the entry/exit color codes of the line. it's needed because we're // splitting the eyes formatting and inserting winston formatting where it // wasn't before. @@ -119,6 +122,7 @@ log.table = function (level, data, transform) { data = level; level = 'data'; } + if (log.format().json) { log.log(level, 'table', data); } else { @@ -186,7 +190,7 @@ cli.progress = function(label) { // Draw initial progress drawAndUpdateProgress(); - + // Draw label if (label) { fs.writeSync(1, ' ' + label); @@ -292,6 +296,7 @@ function enableNestedCommands(command) { var args = command.rawArgs.slice(0, 2); var raw = command.normalize(command.rawArgs.slice(2)); var category = setupCommand(args, raw); + if (!command.categories[category]) { log.error('\'' + category + '\' is not an azure command. See \'azure help\'.'); } else {