@@ -0,0 +1,2948 @@
+/*%0A * LensKit, an open source recommender systems toolkit.%0A * Copyright 2010-2014 LensKit Contributors.  See CONTRIBUTORS.md.%0A * Work on LensKit has been funded by the National Science Foundation under%0A * grants IIS 05-34939, 08-08692, 08-12148, and 10-17697.%0A *%0A * This program is free software; you can redistribute it and/or modify%0A * it under the terms of the GNU Lesser General Public License as%0A * published by the Free Software Foundation; either version 2.1 of the%0A * License, or (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful, but WITHOUT%0A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS%0A * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more%0A * details.%0A *%0A * You should have received a copy of the GNU General Public License along with%0A * this program; if not, write to the Free Software Foundation, Inc., 51%0A * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%0A */%0Apackage org.lenskit.cli.commands;%0A%0Aimport com.google.auto.service.AutoService;%0Aimport com.google.common.io.Files;%0Aimport net.sourceforge.argparse4j.inf.ArgumentParser;%0Aimport net.sourceforge.argparse4j.inf.Namespace;%0Aimport org.lenskit.cli.Command;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport javax.script.ScriptEngine;%0Aimport javax.script.ScriptEngineManager;%0Aimport javax.script.SimpleBindings;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.io.Reader;%0Aimport java.util.List;%0A%0A@AutoService(Command.class)%0Apublic class RunScript implements Command %7B%0A    private static final Logger logger = LoggerFactory.getLogger(RunScript.class);%0A%0A    @Override%0A    public String getName() %7B%0A        return %22run-script%22;%0A    %7D%0A%0A    @Override%0A    public String getHelp() %7B%0A        return %22Run a Groovy script against a LensKit model.%22;%0A    %7D%0A%0A    @Override%0A    public void configureArguments(ArgumentParser parser) %7B%0A        parser.addArgument(%22script%22)%0A              .type(File.class)%0A              .metavar(%22SCRIPT%22)%0A              .help(%22run SCRIPT%22);%0A        parser.addArgument(%22args%22)%0A              .type(String.class)%0A              .nargs(%22*%22)%0A              .metavar(%22ARGS%22)%0A              .help(%22pass ARGS to script%22);%0A    %7D%0A%0A    @Override%0A    public void execute(Namespace options) throws Exception %7B%0A        ScriptEngineManager sem = new ScriptEngineManager();%0A        File scriptFile = options.get(%22script%22);%0A        String ext = Files.getFileExtension(scriptFile.getName());%0A        ScriptEngine engine = sem.getEngineByExtension(ext);%0A        logger.info(%22running %7B%7D with engine %7B%7D%22, scriptFile, engine);%0A        SimpleBindings bindings = new SimpleBindings();%0A        bindings.put(%22logger%22, LoggerFactory.getLogger(scriptFile.getName()));%0A        bindings.put(%22args%22, options.%3CList%3CString%3E%3Eget(%22args%22));%0A        try (Reader reader = new FileReader(scriptFile)) %7B%0A            engine.eval(reader, bindings);%0A        %7D%0A    %7D%0A%7D%0A

Add a rudimentary run-script CLI command (#688)