diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-05-02 13:04:39 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-05-02 13:04:39 +0200 |
commit | e05b4e700ddc22cb86147c6440d4714caf1f391a (patch) | |
tree | a50c68d7aebca6a59f12d2f101435d3f92a0d46b | |
parent | 218bc2bc31677fbcb326bcd88878c46fb39005b0 (diff) | |
download | bitraf-bot-e05b4e700ddc22cb86147c6440d4714caf1f391a.tar.gz bitraf-bot-e05b4e700ddc22cb86147c6440d4714caf1f391a.tar.bz2 bitraf-bot-e05b4e700ddc22cb86147c6440d4714caf1f391a.tar.xz bitraf-bot-e05b4e700ddc22cb86147c6440d4714caf1f391a.zip |
o Better command line opion parsing.
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | main.js | 28 |
2 files changed, 25 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2ce437 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*.un~ +*.swp +node_modules/ @@ -4,15 +4,31 @@ var cmdopt = require('cmdopt') , _ = require('underscore'); var parser = new cmdopt.Parser(); +parser.option("-h, --help", "show help"); +parser.option("-c, --channel=CHANNEL", "IRC channel to join"); +parser.option("-n, --nick=NICK", "Nickname of the bot"); +parser.option("--checkinsUrl", "URL to use when looking for checkins"); -var config = { - channel: '#bitraf2', +var args = process.argv.slice(2); +var defaults = { checkinsUrl: 'http://hermes.bitraf.no/~trygvis/checkins.php', nick: os.hostname() }; -var bot = require('./lib/client.js')(config); +try { + var config = parser.parse(args); + config = _.defaults(config, defaults); + console.log("config", config); + if (config.help) console.log(parser.help()); -var r = repl.start('irc> '); -r.context.bot = bot; -r.context.config = config; + var bot = require('./lib/client.js')(config); + var r = repl.start('irc> '); + r.context.bot = bot; + r.context.config = config; +} catch (ex) { + if (ex instanceof cmdopt.ParseError) { + process.stderr.write(ex.message + "\n"); + process.exit(1); + } + throw ex; +} |