From: Jason Woofenden Date: Mon, 11 Feb 2013 20:51:08 +0000 (-0500) Subject: client.coffee: parse and handle commandline arguments X-Git-Url: https://jasonwoof.com/gitweb/?a=commitdiff_plain;ds=inline;h=dccb74d142d2e2d54533bfd2006988d8c8ac4603;p=af-coffee.git client.coffee: parse and handle commandline arguments --- diff --git a/client.coffee b/client.coffee old mode 100644 new mode 100755 index a378480..8ae4715 --- a/client.coffee +++ b/client.coffee @@ -1,3 +1,5 @@ +#!/usr/bin/coffee + fs = require 'fs' async = require 'async' af = require './api.coffee' @@ -74,3 +76,25 @@ login = (callback) -> exports.new_session = -> return new Session() + +usage = -> + console.log "usage: #{process.argv[0]} #{process.argv[1]} command [args...]" + console.log "valid commands are:" + for k, v of af + console.log "\t#{k}" unless k is 'login' + +# parse and act on commandline arguments unless we were require()d as a module +if require.main is module + args = process.argv[2..] + if args.length is 0 + usage() + else if not af[args[0]] + console.log "unknown command \"#{args[0]}\"" + usage() + else + session = new Session() + session.api args[0], args[1..], (err, result) -> + if err? + console.log "error: ", err + if result? + console.log "result: ", result