Skip to content

Commit

Permalink
FORGE-2630: Using configured option name style
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 28, 2016
1 parent c447696 commit 0bac7d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private List<String> resolveWildcardSelectOptionValues(CommandLine<?> commandLin
return resolvedOptionValues;
}

private String toOptionName(String name)
public String toOptionName(String name)
{
String optionNameStyle = userConfig.getString(OPTION_STYLE_PROPERTY, DASHED_OPTION_STYLE);
return DASHED_OPTION_STYLE.equals(optionNameStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class ForgeCommandRegistry implements CommandRegistry

private final CommandFactory commandFactory;
private final CommandRegistry aeshCommandRegistry;
private final AddonRegistry addonRegistry;

private CommandLineUtil commandLineUtil;
private final CommandControllerFactory commandControllerFactory;
Expand All @@ -63,14 +62,15 @@ public ForgeCommandRegistry(Furnace furnace, ShellImpl shell, AddonRegistry addo
{
this.furnace = furnace;
this.shell = shell;
this.addonRegistry = addonRegistry;
this.commandFactory = addonRegistry.getServices(CommandFactory.class).get();
this.commandControllerFactory = addonRegistry.getServices(CommandControllerFactory.class).get();
this.commandLineUtil = new CommandLineUtil(addonRegistry);
ConverterFactory converterFactory = addonRegistry.getServices(ConverterFactory.class).get();
InputComponentFactory inputComponentFactory = addonRegistry.getServices(InputComponentFactory.class).get();

// Use Aesh commands
Man manCommand = new Man(new ForgeManProvider(shell, commandFactory, converterFactory, inputComponentFactory));
Man manCommand = new Man(
new ForgeManProvider(shell, commandFactory, converterFactory, inputComponentFactory, commandLineUtil));
this.aeshCommandRegistry = new AeshCommandRegistryBuilder()
.command(Grep.class)
.command(Less.class)
Expand Down Expand Up @@ -105,7 +105,7 @@ public CommandContainer<?> getCommand(String name, String completeLine) throws C
{
// Do nothing
}
ShellSingleCommand cmd = new ShellSingleCommand(controller, shellContext, getCommandLineUtil());
ShellSingleCommand cmd = new ShellSingleCommand(controller, shellContext, commandLineUtil);
CommandAdapter commandAdapter = new CommandAdapter(shell, shellContext, cmd);
return new ForgeCommandContainer(shellContext, aeshCommand.getCommandLineParser(), commandAdapter);
}
Expand Down Expand Up @@ -138,32 +138,22 @@ private CommandContainer<?> getForgeCommand(ShellContextImpl shellContext, Strin
private AbstractShellInteraction findCommand(ShellContext shellContext, String commandName)
{
AbstractShellInteraction result = null;
CommandLineUtil cmdLineUtil = getCommandLineUtil();
UICommand cmd = commandFactory.getNewCommandByName(shellContext, commandName);
if (cmd != null && cmd.isEnabled(shellContext))
{
CommandController controller = commandControllerFactory.createController(shellContext, shell, cmd);
if (controller instanceof WizardCommandController)
{
result = new ShellWizard((WizardCommandController) controller, shellContext, cmdLineUtil, this);
result = new ShellWizard((WizardCommandController) controller, shellContext, commandLineUtil, this);
}
else
{
result = new ShellSingleCommand(controller, shellContext, cmdLineUtil);
result = new ShellSingleCommand(controller, shellContext, commandLineUtil);
}
}
return result;
}

private CommandLineUtil getCommandLineUtil()
{
if (commandLineUtil == null)
{
commandLineUtil = new CommandLineUtil(addonRegistry);
}
return commandLineUtil;
}

@Override
public Set<String> getAllCommandNames()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jboss.forge.addon.ui.input.InputComponentFactory;
import org.jboss.forge.addon.ui.input.ManyValued;
import org.jboss.forge.addon.ui.input.SelectComponent;
import org.jboss.forge.addon.ui.util.Commands;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.addon.ui.wizard.UIWizard;
import org.jboss.forge.furnace.util.OperatingSystemUtils;
Expand All @@ -52,31 +51,21 @@ public class ForgeManProvider implements ManProvider
private final CommandFactory manager;
private final ConverterFactory converterFactory;
private final InputComponentFactory inputComponentFactory;
private final Comparator<? super InputComponent<?, ?>> SHORTNAME_COMPARATOR = new Comparator<InputComponent<?, ?>>()
{
@Override
public int compare(InputComponent<?, ?> left, InputComponent<?, ?> right)
{
return Character.valueOf(left.getShortName()).compareTo(right.getShortName());
}
};
private final CommandLineUtil commandLineUtil;
private final Comparator<? super InputComponent<?, ?>> SHORTNAME_COMPARATOR = (left, right) -> Character
.valueOf(left.getShortName()).compareTo(right.getShortName());

private final Comparator<? super InputComponent<?, ?>> NAME_COMPARATOR = new Comparator<InputComponent<?, ?>>()
{
@Override
public int compare(InputComponent<?, ?> left, InputComponent<?, ?> right)
{
return left.getName().compareTo(right.getName());
}
};
private final Comparator<? super InputComponent<?, ?>> NAME_COMPARATOR = (left, right) -> left.getName()
.compareTo(right.getName());

public ForgeManProvider(ShellImpl shell, CommandFactory manager, ConverterFactory converterFactory,
InputComponentFactory inputComponentFactory)
InputComponentFactory inputComponentFactory, CommandLineUtil commandLineUtil)
{
this.shell = shell;
this.manager = manager;
this.converterFactory = converterFactory;
this.inputComponentFactory = inputComponentFactory;
this.commandLineUtil = commandLineUtil;
}

@Override
Expand Down Expand Up @@ -195,7 +184,7 @@ else if (input.isRequired())
{
result.append("-").append(input.getShortName()).append(" ");
}
result.append("--").append(Commands.shellifyOptionName(input.getName())).append("] ");
result.append("--").append(commandLineUtil.toOptionName(input.getName())).append("] ");
result.append(input.getValueType().getSimpleName()).append(" ");
}
}
Expand Down Expand Up @@ -237,7 +226,7 @@ private String buildOptions(UICommand cmd, UIContext context, List<InputComponen
else
result.append(" ");

result.append("--").append(Commands.shellifyOptionName(input.getName())).append("*");
result.append("--").append(commandLineUtil.toOptionName(input.getName())).append("*");
result.append(OperatingSystemUtils.getLineSeparator());
result.append(" ");

Expand Down

0 comments on commit 0bac7d2

Please sign in to comment.