davidchambers/tutor — pull request #26 by nicknovitski (2012-08-19 22:06:45+00:00)
Title: Adding a command-line interface

Currently, all it does is call fetch_card.

$ tutor Forest
Forest
Basic Land - Forest
G
$ tutor 11184
Wall of Bone	{2}{B}
Creature - Skeleton Wall	(1/4)
Defender (This creature can't attack.)

{B}: Regenerate Wall of Bone. (The next time this creature would be destroyed this turn, it isn't. Instead tap it, remove all damage from it, and remove it from combat.)
Revised Edition Uncommon

I'm hardly married to this specific presentation, it's just my first pass at a compact display of what info people would want. Is the Set/Rarity line needed? Is there anything missing? Maybe alternate templates could be used with command line options, like `--verbose` or something.

Another thing I could add before merging is set requests, preferably using parameters, like `tutor -s` or `tutor --set`. That's probably best handled with an option parsing library like [https://github.com/substack/node-optimist](optimist). I mean, I realize that currently, out requests to gatherer aren't fully parametrized (ie, we can't search where set = "something" and name includes "word"), but I'm trying to think of what my ideal command line interface for getting card information would be. And maybe someday we'll have a real database to query from.

Proper testing of a module like this required mocking. I used Sinon.js for that, and it turns out to be pretty easy to use. Which is great, because I have a philosophical imperative to write the tests for the gatherer and server modules in the same style!

Speaking of which, I changed the api for the gatherer module so that it expects an object with named properties, and the server module to turn express' request parameters into such an object.