From: Jason Woofenden Date: Tue, 12 Feb 2013 14:10:36 +0000 (-0500) Subject: be verbose (print api calls) X-Git-Url: https://jasonwoof.com/gitweb/?p=af-coffee.git;a=commitdiff_plain;h=ac50f2ea803eb6d5e59aa8309df328ea81573fcd be verbose (print api calls) --- diff --git a/client.coffee b/client.coffee index 84fff91..a7dbca5 100755 --- a/client.coffee +++ b/client.coffee @@ -52,6 +52,31 @@ commands.app_restart = (token, app_name, callback) -> class Session constructor: -> @token = 0 + @verbose = true + @log_nest = 0 + @log_mid = false + + log_whitespace: -> + out = '' + out += '\n' if @log_mid + for i in [0...@log_nest] + out += '\t' + return out + + log_start: (msg) -> + return unless @verbose + process.stdout.write "#{@log_whitespace()}#{msg}" + @log_nest += 1 + @log_mid = true + + log_end: -> + return unless @verbose + @log_nest -= 1 + if @log_mid + process.stdout.write "... done\n" + else + process.stdout.write "#{@log_whitespace()}done\n" + @log_mid = false api: (call, args..., callback) -> async.waterfall [ @@ -65,8 +90,11 @@ class Session callback null, @token (token, callback) => @token = token + @log_start [call, args...].join ' ' # commands implemented in client.coffee need "this" pointing to the session - commands[call].call this, @token, args..., callback + commands[call].call this, @token, args..., (err, the_rest...) => + @log_end() unless err? + callback err, the_rest... ], (err, result) => # eg /app/xxx/stats sometimes returns 404 with wrong auth token if err?.code is 403 or err?.code is 404