JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
be verbose (print api calls)
authorJason Woofenden <jason@jasonwoof.com>
Tue, 12 Feb 2013 14:10:36 +0000 (09:10 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 12 Feb 2013 14:10:36 +0000 (09:10 -0500)
client.coffee

index 84fff91..a7dbca5 100755 (executable)
@@ -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