improvements needed for making a command-line tool #82

wants to merge 9 commits into


None yet
5 participants

mislav commented Oct 27, 2011

I wanted to make my own hubot on command-line, but the current Robot base class was missing several essential features.

  1. Hubot scripts are loaded asynchronously, but there's no callback for when that's done. I can't know when listeners are ready.
  2. I can't detect when no listener has matched a message. I need the cmdline tool to error out in this case.
  3. Hubot outputs all listener regexes to stdout on start, probably for debugging.

Features I've added should be non-invasive. Tell me what you think.

I now have my very own hubot command-line tool:

$ open $(hubot mustache me vin diesel)

Is this something you might want in as a separate adapter? It's different than shell adapter since it only takes a single command and then exits.


holman commented Oct 27, 2011

I've wanted something like this just for the sake of testing scripts too, so I didn't have to start a shell, run it, quit it, and repeat.


technoweenie commented Oct 27, 2011

Oh nice, love the load callback. I was going to investigate that at some point. Ideally it could wait for a callback from the brain telling it that it's ready (with fresh data from redis).

mislav commented Oct 27, 2011

Here's my implementation so far (dependent on these changes). Pretty straightforward, with the exception of the horrid @imminentDeath hack. The problem is we can't know when a matched listener has stopped performing, since it can call send or reply multiple times asynchronously. So I activate a timeout on each send that kills the process if nothing happens in the next 10 ms.


atmos commented Oct 27, 2011

I'll see about merging this after the next release. Looks awesome @mislav.

mtodd commented Oct 27, 2011

Perhaps we could add a debug flag to enable outputting the regexes and various other debugging information? This would make using hubot on the CLI a little more useful for testing some scripts out.

Love it. 👍

mislav commented Oct 28, 2011

@mtodd: I've just added a general "-q" ("--quiet") option to bin/hubot. It configures the robot instance to not output debugging info on STDOUT. I've changed the method signatures of Hubot.loadBot and new Robot, however: see a298bb2. A Robot instance now just accepts a single parameter which is an options hash, instead of two optional parameters (scripts path and robot name).

The upside of this backwards-incompatible change is, apart from supporting the "--quiet" option, that debug and err streams of each Robot instance are now configurable. You can set them to log to a file, for instance.

I've also added my "Cli" adapter:

$ hubot -a cli -q -- "image me happy"

@atmos atmos commented on the diff Oct 28, 2011

Parser.on "version", (opt, value) ->
Options.version = true
-Parser.parse process.ARGV
+argv = process.argv.slice 2
+# don't process arguments after "--"
+if (idx = argv.indexOf '--') >= 0

atmos Oct 28, 2011


Is there some other way to do this? Seems weird.


atmos commented Oct 28, 2011

Closing in favor of #87.

atmos closed this Oct 28, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment