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 [
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