From: Jason Woofenden Date: Mon, 11 Feb 2013 21:09:43 +0000 (-0500) Subject: errors and warnings to stderr X-Git-Url: https://jasonwoof.com/gitweb/?p=af-coffee.git;a=commitdiff_plain;h=f4eb811f6b6194f889c676fa7fd327fd1f50789f errors and warnings to stderr --- diff --git a/client.coffee b/client.coffee index 8ae4715..ccb26b3 100755 --- a/client.coffee +++ b/client.coffee @@ -68,7 +68,7 @@ login = (callback) -> # wait for file write so there's no race condition if get_token gets called soon fs.writeFile token_file, token, (err) -> if err - console.log "Warning: couldn't cache auth token in #{token_file}: ", err + process.stderr.write "Warning: couldn't cache auth token in #{token_file}: #{err}\n" # don't pass on error, it's ok if we can't cache it callback null, token ], callback @@ -78,10 +78,10 @@ exports.new_session = -> return new Session() usage = -> - console.log "usage: #{process.argv[0]} #{process.argv[1]} command [args...]" - console.log "valid commands are:" + process.stderr.write "usage: #{process.argv[0]} #{process.argv[1]} command [args...]\n" + process.stderr.write "valid commands are:\n" for k, v of af - console.log "\t#{k}" unless k is 'login' + process.stderr.write "\t#{k}\n" unless k is 'login' # parse and act on commandline arguments unless we were require()d as a module if require.main is module @@ -89,12 +89,15 @@ if require.main is module if args.length is 0 usage() else if not af[args[0]] - console.log "unknown command \"#{args[0]}\"" + process.stderr.write "unknown command \"#{args[0]}\"\n" usage() else session = new Session() session.api args[0], args[1..], (err, result) -> if err? - console.log "error: ", err + process.stderr.write "Error: #{JSON.stringify err}\n" if result? - console.log "result: ", result + if typeof result is 'string' + process.stdout.write result + else + process.stdout.write JSON.stringify result