This topic contains information about providing new command line tasks.
The preferred way to create a cliTask handler is place a groovy script in the app/tasks directory. The virtual directory feature of zero will automatically find the new cliTasks. The groovy script provides an implementation of onCliTask.
If the task handler is written in java, then the handler is added to the configuration handlers using the cliTask event.
# MyTask /config/handlers += [{ "events": "cliTask", "handler" : "zero.simple.task.MyTask.class", "conditions" : "/event/task =~ mytask" }]
The java based task must provide an implementation of the method onCliTask and the GlobalContext is used to obtain the event args.
public void onCliTask() { List<String> args = GlobalContext.zget("/event/args"); ... }
A cliTask handler may need know what the current directory is. This can be obtained from the system property user.dir.
The command line task support also supports grouping a set of tasks as subtasks. The following snippet shows how to define a subtask. The event/task is used to define the task name, and then event/subTask defines the subtask. The condition match will case the onCliSubTask method of the handler to be invoked.
# MySubTask /config/handlers += [{ "events": "cliSubTask", "handler" : "zero.simple.task.MySubTask.class", "conditions" : "(/event/task =~ mytask) && (/event/subTask =~ mysubtask)" }]
Invoking the task directly, zero mytask, will display the help for the task and all of the subtasks. Each subtask is invoked through the command line using zero mytask subtask.
The task implementation may need access to where the task was invoked from and where the zero home is. The system property user.dir can be used to determine where the task was invoked from, but this may not be desired information. The command line supports a walk up feature where tasks for a module can be invoked from any directory under the module. The apphome is the root directory of the module and can be obtained from the event zone, event/apphome. The root directory of the module is probably more useful to find zero artifacts like the config directory.
static public File getAppRoot() { File app = zget("/event/apphome"); return app; }
Some task may also need know where the command line was installed, also referred to as zerohome. The command line scrips set zerohome as an environment property.
String zerohome = System.getenv("ZERO_HOME");
Each task should provide help by placing the help text in the app/tasks/help folder. The help system provides i18n support by using subfolders for language and country.
The name of the help will be mytask_full.txt and mytask_short.txt. The short text is display for zero help which displays the help for all cliTasks. The full text is displayed when help for an specific task is requested, zero help mytask;