org.snapscript.common.command.CommandBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.common.command;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Callable;
public class CommandBuilder {
private final String directory;
private final boolean redirect;
private final boolean wait;
public CommandBuilder() {
this(".");
}
public CommandBuilder(String directory) {
this(directory, false);
}
public CommandBuilder(String directory, boolean redirect) {
this(directory, redirect, true);
}
public CommandBuilder(String directory, boolean redirect, boolean wait) {
this.directory = directory;
this.redirect = redirect;
this.wait = wait;
}
public Callable create(String source) throws Exception {
return create(source, directory);
}
public Callable create(String source, String directory) throws Exception {
return create(source, directory, Collections.EMPTY_MAP);
}
public Callable create(String source, Map context) throws Exception {
return create(source, directory, context);
}
public Callable create(String source, String directory, Map context) throws Exception {
File path = new File(directory);
Environment environment = new MapEnvironment(context);
Command command = new ProcessCommand(source, path, redirect, wait);
return new CommandOperation(command, environment);
}
}