Part of old CH CLI - A framework for building CLIs for REST APIs very easily.
Java Shell Groovy XML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
maven-plugin
runtime
.gitattributes
.gitignore
README.md
pom.xml

README.md

Mule Jockey is a simple way to build CLIs using Groovy, with a focus on making it especially easy to interact with remote REST services.

Given a command like this:

import com.mulesoft.jockey.*;  
@Command("test")
@Options([
  @Option(name="n",longName="name",description="Your name",optional=false)
])
public class TestCommand extends GroovyCommand {
    void execute() {
        println "Hello " + name;
    }
}

Mule Jockey will create a test.sh and a test.bat file inside a distribution that will execute it. It will also take the command line parameter -n or --name and inject it into your command as a name field.

Quick Start

  1. Create your project

    $ mkdir testcli $ cd testcli

  2. Create a pom.xml

    4.0.0 com.mulesoft.ion testcli Test CLI tools 1.0
    com.mulesoft mule-jockey 1.0-SNAPSHOT
    com.mulesoft mule-jockey-maven-plugin 1.0-SNAPSHOT ion-cli-${version} package generate
    java.net http://download.java.net/maven/2/ mule-releases http://repository.muleforge.org/release/ mule-snapshots Mule Snapshot Repository http://repository.muleforge.org/snapshot/ true

  3. Create your source directory

    $ mkdir src/main/groovy

  4. Edit your first command, testcli/src/main/groovy/TestCommand.groovy and enter the following:

    import com.mulesoft.jockey.*;
    @Command("test") @Options([ @Option(name="n",longName="name",description="Your name",optional=false) ]) public class TestCommand extends GroovyCommand { void execute() { println "Hello " + name; } }

  5. Build your CLI

    $ mvn install

  6. Test it out:

    $ unzip target/test-1.0.zip $ cd test-1.0 $ ./bin/test.sh -h usage: test -h,--help Print out help for this command. -n,--name Your name $ ./bin/test.sh -n Dan Hello Dan

Writing HTTP Based Commands

Mule Jockey will inject a copy of a Jersey client into your commands so that you can easily talk to RESTful services. This makes it extremely easy to talk to JSON based services. For example:

import com.mulesoft.jockey.*
import com.sun.jersey.api.client.ClientResponse  

@Command("list-some-things")
@Options([
    @Option(name="x", longName="url", description="URL", defaultValue="http://localhost/api"),
    @Option(name="u", longName="username", description="Username", defaultValue="admin"),
    @Option(name="p", longName="password", description="Password", defaultValue="admin"),
])
public class ListSomeThings extends  {
    void execute() {
        client.addFilter(new HTTPBasicAuthFilter(username, password));
        
        def response = client.resource("${url}/somethings")
                             .get(ClientResponse.class);

        def values = response.getEntity(Map[].class);
        values.each { 
            println "${it}";
        }
    }
}

See here for more info about the Jersey Client API: http://jersey.java.net/nonav/apidocs/latest/jersey/index.html