class RunScriptTool implements Tool {

    @Override
    public void run(CommandLine line, ToolRunningContext context) {
        Path file = context.getFileSystem().getPath(line.getOptionValue(FILE));
        if (file.getFileName().toString().endsWith(".groovy")) {
            try {
                Binding binding = new Binding();
                binding.setProperty("args", line.getArgs());
                GroovyScripts.run(file, binding, context.getOutputStream());
            } catch (Exception e) {
                Throwable rootCause = StackTraceUtils.sanitizeRootCause(e);
                rootCause.printStackTrace(context.getErrorStream());
            }
        } else {
            throw new IllegalArgumentException("Script type not supported");
        }
    }

}