(Quick Reference)

4.8 The Griffon Shell - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

4.8 The Griffon Shell

Starting with Griffon 0.9.5 there's a new command line tool at your disposal: the Griffon Shell or griffonsh for short. This is an interactive shell that can be kept running in the background, this way you don't pay the penalty of starting a new JVM every time you invoke a command. Other benefits are the bypass of dependency resolution if dependencies have not changed from the last command invocation. Here's a sample usage session:

$ griffonsh
Welcome to Griffon 1.2.0 - http://griffon-framework.org/
Licensed under Apache Standard License 2.0
Griffon home is set to: /usr/local/griffon

Type 'exit' or ^D to terminate this interactive shell

griffon> compile Resolving dependencies… Dependencies resolved in 903ms. Environment set to development Resolving plugin dependencies … Plugin dependencies resolved in 1502 ms. [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/classes/cli [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/classes/main [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/classes/test [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/test-classes [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/test-resources [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/resources [griffonc] Compiling 8 source files to /Users/joe/.griffon/1.2.0/projects/sample/classes/main [griffonc] Compiling 4 source files to /Users/joe/.griffon/1.2.0/projects/sample/classes/main griffon> run-app Resolving dependencies… Dependencies resolved in 1ms. [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/resources/griffon-app/i18n [mkdir] Created dir: /Users/joe/.griffon/1.2.0/projects/sample/resources/griffon-app/resources [copy] Copying 1 file to /Users/joe/.griffon/1.2.0/projects/sample/resources/griffon-app/i18n [copy] Copying 8 files to /Users/joe/.griffon/1.2.0/projects/sample/resources/griffon-app/resources [copy] Copying 1 file to /Users/joe/.griffon/1.2.0/projects/sample/classes/main [copy] Copying 11 files to /Users/joe/.griffon/1.2.0/projects/sample/resources [copy] Copied 8 empty directories to 8 empty directories under /Users/joe/.griffon/1.2.0/projects/sample/resources [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging [copy] Copying 1 file to /projects/sample/staging Launching application … 2012-02-07 17:27:11,007 [main] INFO griffon.swing.SwingApplication - Initializing all startup groups: [sample] 2012-02-07 17:27:16,555 [AWT-EventQueue-0] INFO griffon.swing.SwingApplication - Shutdown is in process [delete] Deleting directory /projects/sample/staging/macosx64 [delete] Deleting directory /projects/sample/staging/macosx griffon> clean Resolving dependencies… Dependencies resolved in 1ms. [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/classes/cli [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/classes/main [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/classes/test [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/test-classes [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/test-resources [delete] Deleting directory /Users/joe/.griffon/1.2.0/projects/sample/resources [delete] Deleting directory /projects/sample/staging griffon>

This command environment accepts all commands available to the griffon command (except those that let you create a new project) plus a few more that are unique to the griffon shell. Please refer to the help command for more information on those extra commands.

4.8.1 Adding Command Help and Options

All commands from the standard Griffon distribution are supported in griffonsh. Should you choose to integrate your own commands (currently restricted to those delivered by a plugin) then you must generate an additional set of files. The create-script explained in the Scripts section has an on option for doing just that.

Say for example you'd want to provide support for a command called create-page, this is how it can be done

griffon create-script create-page --with-command-support=true

The following files will be created by the previous command:

scripts/CreatePage.groovy

This is the command itself. It contains the code that makes the script work.

test/cli/CreatePageTests.groovy

No Griffon artifact is complete without a test harness.

src/cli/org/codehaus/griffon/cli/shell/help/create-page.txt

This file contains the help text that should be presented to the user when the griffon help command is issued, like this

griffon help create-page

This file typically contains the formatted text obtained by running griffonsh help on the script itself.

src/cli/org/codehaus/griffon/cli/shell/command/CreatePageCommand.java
src/cli/org/codehaus/griffon/cli/shell/command/create-page.txt

These two files contain the shell hints (CreatePageCommand.java) and an optional extended detail section (create-page.txt). The Java class supports both options and arguments. It's important to note that argument names must match their field names, as suggested by the defualt template shown here

package org.codehaus.griffon.cli.shell.command;

import org.codehaus.griffon.cli.shell.AbstractGriffonCommand; import org.codehaus.griffon.cli.shell.Command; import org.codehaus.griffon.cli.shell.Argument; import org.codehaus.griffon.cli.shell.Option;

@Command(scope = "myplugin", name = "create-page", description = "Single line description goes here", detailedDescription = "classpath:create-page.txt") public class CreatePageCommand extends AbstractGriffonCommand { /* @Option(name = "--foo", description = "Description of foo option.", required = false) private String foo;

@Argument(index = 0, name = "bar", description = "Description of first argument.", required = false) private String bar; */ }

Multiple values may be specified as arguments, here's how the run-app command does it

@Argument(index = 0,
        name = "arguments",
        description = "Optional arguments to be passed to the application.",
        required = false,
        multiValued = true)
private List<String> arguments;