import org.fusesource.jansi.Ansi;
public class DefaultActionPreparator implements ActionPreparator {
public boolean prepare(Action action, CommandSession session, List<Object> params) throws Exception {
ActionMetaData actionMetaData = new ActionMetaDataFactory().create(action.getClass());
Map<Option, Field> options = actionMetaData.getOptions();
Map<Argument, Field> arguments = actionMetaData.getArguments();
List<Argument> orderedArguments = actionMetaData.getOrderedArguments();
Command command2 = actionMetaData.getCommand();
if (command2 == null) {
// to avoid NPE with subshell
return true;
}
String commandErrorSt = (command2 != null) ? Ansi.ansi()
.fg(Ansi.Color.RED)
.a("Error executing command ")
.a(command2.scope())
.a(":")
.a(Ansi.Attribute.INTENSITY_BOLD)
.a(command2.name())
.a(Ansi.Attribute.INTENSITY_BOLD_OFF)
.fg(Ansi.Color.DEFAULT)
.a(": ")
.toString() : "";
for (Iterator<Object> it = params.iterator(); it.hasNext(); ) {
Object param = it.next();
if (HelpOption.HELP.name().equals(param)) {
Terminal term = session != null ? (Terminal) session.get(".jline.terminal") : null;
int termWidth = term != null ? term.getWidth() : 80;
boolean globalScope = NameScoping.isGlobalScope(session, actionMetaData.getCommand().scope());
actionMetaData.printUsage(action, System.out, globalScope, termWidth);
return false;
}
}
// Populate