use of de.vandermeer.asciitable.v2.V2_AsciiTable in project walkmod-core by walkmod.
the class WalkModDispatcher method execute.
public void execute(JCommander jcommander, String[] args) throws Exception {
commands.put("add", new AddTransformationCommand(jcommander));
commands.put("add-excludes", new AddExcludesCommand(jcommander));
commands.put("add-includes", new AddIncludesCommand(jcommander));
commands.put("add-module", new AddModuleCommand(jcommander));
commands.put("add-plugin", new AddPluginCommand(jcommander));
commands.put("add-provider", new AddCfgProviderCommand(jcommander));
commands.put("apply", new ApplyCommand(jcommander));
commands.put("chains", new PrintChainsCommand(jcommander));
commands.put("check", new CheckCommand(jcommander));
commands.put("init", new InitCommand(jcommander));
commands.put("inspect", new InspectCommand(jcommander));
commands.put("install", new InstallCommand(jcommander));
commands.put("modules", new PrintModulesCommand(jcommander));
commands.put("patch", new PatchCommand(jcommander));
commands.put("providers", new PrintProvidersCommand(jcommander));
commands.put("rm", new RemoveTransformationCommand(jcommander));
commands.put("rm-excludes", new RemoveExcludesCommand(jcommander));
commands.put("rm-includes", new RemoveIncludesCommand(jcommander));
commands.put("rm-chain", new RemoveChainCommand(jcommander));
commands.put("rm-module", new RemoveModuleCommand(jcommander));
commands.put("rm-plugin", new RemovePluginCommand(jcommander));
commands.put("rm-provider", new RemoveProviderCommand(jcommander));
commands.put("set-reader", new SetReaderCommand(jcommander));
commands.put("set-writer", new SetWriterCommand(jcommander));
commands.put("transformations", new PrintTransformationsCommand(jcommander));
commands.put("plugins", new PrintPluginsCommand(jcommander));
commands.put("--version", new VersionCommand());
commands.put("--help", new HelpCommand(jcommander));
Set<String> keys = commands.keySet();
for (String key : keys) {
if (!key.startsWith("--")) {
jcommander.addCommand(key, commands.get(key));
} else {
jcommander.addCommand(key, commands.get(key), "-" + key.charAt(2));
}
JCommander aux = jcommander.getCommands().get(key);
aux.setProgramName("walkmod " + key);
aux.setAcceptUnknownOptions(false);
}
if (args == null || args.length == 0) {
printHeader();
new HelpCommand(jcommander).execute();
} else {
try {
jcommander.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
System.out.println("Run walkmod --help to see the accepted parameters");
return;
}
String command = jcommander.getParsedCommand();
printHeader();
Command commandObject = commands.get(command.substring("walkmod ".length(), command.length()));
commandObject.execute();
if (commandObject instanceof AsciiTableAware) {
AsciiTableAware aux = (AsciiTableAware) commandObject;
V2_AsciiTable table = aux.getTable();
if (table != null) {
V2_AsciiTableRenderer rend = new V2_AsciiTableRenderer();
rend.setTheme(V2_E_TableThemes.UTF_LIGHT.get());
rend.setWidth(new AsciiTableWidth(50));
RenderedTable rt = rend.render(table);
System.out.println(rt);
}
}
}
}
use of de.vandermeer.asciitable.v2.V2_AsciiTable in project walkmod-core by walkmod.
the class PrintModulesCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("modules");
} else {
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
Configuration cfg = facade.getConfiguration();
if (cfg == null) {
log.error("Sorry, the current directory does not contain a walkmod configuration file or it is invalid.");
}
at = new V2_AsciiTable();
at.addRule();
at.addRow("MODULE");
at.addRule();
if (cfg != null) {
List<String> modules = cfg.getModules();
if (modules != null) {
for (String module : modules) {
at.addRow(module);
}
}
}
at.addRule();
}
}
use of de.vandermeer.asciitable.v2.V2_AsciiTable in project walkmod-core by walkmod.
the class PrintTransformationsCommand method execute.
@Override
public void execute() throws Exception {
if (help) {
command.usage("transformations");
} else {
if (chain == null) {
chain = new LinkedList<String>();
}
if (chain.isEmpty()) {
chain.add("default");
}
WalkModFacade facade = new WalkModFacade(OptionsBuilder.options());
Configuration cfg = facade.getConfiguration();
if (cfg != null) {
Collection<ChainConfig> chains = cfg.getChainConfigs();
if (chains != null) {
Iterator<ChainConfig> it = chains.iterator();
ChainConfig selected = null;
while (it.hasNext() && selected == null) {
ChainConfig current = it.next();
if (current.getName().equals(chain.get(0))) {
selected = current;
}
}
if (selected != null) {
at = new V2_AsciiTable();
at.addRule();
at.addRow("TRANSFORMATION TYPE", "PARAMETERS", "NAME/ALIAS");
at.addStrongRule();
List<TransformationConfig> transformations = selected.getWalkerConfig().getTransformations();
if (transformations != null) {
for (TransformationConfig transf : transformations) {
Map<String, Object> parameters = transf.getParameters();
if (parameters == null || parameters.isEmpty()) {
at.addRow(transf.getType(), "", transf.getName());
} else {
Set<String> keys = parameters.keySet();
int i = 0;
for (String key : keys) {
if (i == 0) {
String name = transf.getName();
if (name == null) {
name = "";
}
at.addRow(transf.getType(), "-" + key + ":" + parameters.get(key), "");
} else {
at.addRow("", "-" + key + ":" + parameters.get(key), "");
}
i++;
}
}
at.addRule();
}
}
}
}
} else {
log.error("Sorry, the current directory does not contain a walkmod configuration file or it is invalid.");
at = new V2_AsciiTable();
at.addRule();
at.addRow("TRANSFORMATION TYPE", "PARAMETERS", "NAME/ALIAS");
at.addStrongRule();
at.addRule();
}
}
}
Aggregations