davidchambers / tutor

JavaScript interface for the Gatherer card database
https://gatherer.wizards.com/
Do What The F*ck You Want To Public License
149 stars 18 forks source link

Adding a command-line interface #26

Closed nicknovitski closed 11 years ago

nicknovitski commented 12 years ago

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

nicknovitski commented 12 years ago

Good points, especially on responder. Also I noticed I did something incredibly stupid and broke /language!

nicknovitski commented 12 years ago

Okay, much nicer now. All the parametrized routes use responder just like they used to. The "index" routes could use responder also, but I wasn't sure if they should.

davidchambers commented 11 years ago

Building a CLI should now be rather easy (with the new JavaScript API). Feel free to submit a new pull request. :)