Exit Full View

jguifier

Rather than parse the command line arguments in each script, your scripts define the arguments, including an id, a human readable label, their type, and optionally a short description.

For example, a simple integer with possible values between 1 and 10 is defined like so :

countParameter = new IntegerParameter("count").range(1, 10).description( "your-description-here" );

A simple string

myString = new StringParameter( "myString" );

myFile = new FileParameter( "myFile" ).exists(true).directory();

Extend the Task class, adding a suitable constructor and define the "run" method :

public class MyTask extends Task
{
    // Define each parameter as a class attribute here (i.e. countParameter, myString and myFile).
    
    public MyTask()
    {
        super( "My Task" );
        addParameters( countParameter, myString, myFile );
    }
    
    public void run()
    {
        // Your code goes here
    }
}

Finally instantiate your class, and call the "go" method :

new MyTask().go( argv );

Groovy Scripts

To make launching scripts as easy as possible, create a shell script to launch your tools written in groovy, with the appropriate path. For example :

#!/bin/sh

groovy -cp "/path/to/the/jar/file/jguifier-0.1.jar" "$@"

Then place a "shebang" at the top of each of your ".groovy" files like so :

#!/usr/bin/env jguifier

Where "jguifier" is the name of the shell script. (The shell script has to be on your path, the groovy script doesn't).

You can of course, add additional jars to the classpath to suit your needs. Dynamically adding jars to the classpath within your script is possible, but it's a PITA.

GUI vs TUI (--prompt and --no-prompt)

When you run a script, the default behaviour is to display the GUI if one or more parameters are missing, or otherwise incorrect. If all parameters are ok, then the GUI is not displayed, and your script's run method is called. You can change this behviour, by using the "--prompt" and "--noprompt" options.

"--no-promp" prevents the GUI from appearing even when parameters are missing (in which case stderr will show an error message, and the script exits without doing anything more).

"--prompt" forces the GUI to appear even if the parameter are all present and correct.

Auto Complete

To enable tab-completion when using the linux command line, add the following to ~/.bash_completion :

_JGuifierComplete ()
{
  COMPREPLY=( $(${COMP_WORDS[0]} --autocomplete "${COMP_CWORD}" "${COMP_WORDS[@]}" ) )

  return 0
}

# This assumed that all the groovy scripts in your bin directory use jguifier :
JGUIFIER_SCRIPTS=`cd ~/bin;echo *.groovy`

complete -F _JGuifierComplete -o filenames ${JGUIFIER_SCRIPTS}

Ensure that ~/.bash_completion is sourced (executed) from within your ~/.bashrc. You will need to start a new bash shell for changes to ~/.bash_completion to take effect.

Compile

I use gradle to build the project, like so :

gradle build
gradle javadoc

Note, I don't use the installApp target, as I only need the to build the jar file.

(I then manually copy build/docs to my public website for easy viewing).

To install it into my local repository (so that other projects can use its classes - FileLister and Exec are very useful!)

gradle install