How many web sites/web services have you wished you could just interact with over the command line? Sometimes, you just want to type commands in your shell. I can name at least 3 of our products which I’ve wished I could do that with: iON, MMC, and Tcat.
There are some challenges though. Bash/BAT file scripts don’t provide facilities to interact with web services. Then, if you go with a cross platform language, you have to write cross platform scripts and provide a way to distribute it.
We thought we’d make this easier, so we wrote Mule Jockey, a tool to turn annotated groovy scripts into a cross platform distribution of shell scripts.
It’s really easy. First, write your command. For example:
You specify the name of your command via the @Command annotation and options via the @Option annotation. All your options get injected into your application using the longName attribute.
Then you need to create a POM file and run the Maven plugin. See an example here. Run “mvn package” and presto, you have a CLI distribution with scripts which will run on both Windows and *nix.
Now, let’s run your command:
$ unzip test-tools-1.0.zip
$ cd test-tools-1.0
$ ./bin/test -h
-h,--help Print out help for this command.
-n,--name Your name
$ ./bin/test -n Joe
Ok, but what about interacting with web services? Well, that’s pretty easy because we inject the Jersey client into your command for you to use. Check out this command:
Here we’re combining the power of a dynamic language and Jersey client to easily print out the statuses from the Twitter public timeline. You simply read in the JSON response as a list of Maps and refer to all the properties, such as the tweet text, as fields on that object.
Could it get any easier?
We hope that you’ll find Mule Jockey helpful and send us along your feedback . If you’d like to get started using Mule Jersey, you can read the documentation or download the source at the github site.