Skip to content

Commit

Permalink
Supporting ACCEPT_DEFAULTS flag in ShellUIPromptImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 23, 2014
1 parent 7a92924 commit 076001a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.jboss.aesh.console.AeshConsoleBuilder;
import org.jboss.aesh.console.Console;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.aesh.console.export.ExportManager;
import org.jboss.aesh.console.helper.InterruptHook;
import org.jboss.aesh.console.settings.Settings;
Expand Down Expand Up @@ -233,8 +232,6 @@ public UIProgressMonitor createProgressMonitor(UIContext context)
@Override
public UIPrompt createPrompt(UIContext context)
{
CommandInvocation commandInvocation = (CommandInvocation) context.getAttributeMap()
.get(CommandInvocation.class);
return new ShellUIPromptImpl(console, commandInvocation);
return new ShellUIPromptImpl(context, console);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.jboss.aesh.console.AeshConsole;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.input.UIPrompt;

/**
Expand All @@ -20,18 +21,25 @@
*/
public class ShellUIPromptImpl implements UIPrompt
{
private final UIContext context;
private final AeshConsole console;
private final CommandInvocation commandInvocation;

public ShellUIPromptImpl(AeshConsole console, CommandInvocation commandInvocation)
public ShellUIPromptImpl(UIContext context, AeshConsole console)
{
this.context = context;
this.console = console;
this.commandInvocation = commandInvocation;
this.commandInvocation = (CommandInvocation) context.getAttributeMap()
.get(CommandInvocation.class);
}

@Override
public String prompt(String message)
{
if (isAcceptDefaultsEnabled())
{
return null;
}
PrintStream out = console.getShell().out();
out.print(message);
String output;
Expand All @@ -50,6 +58,10 @@ public String prompt(String message)
@Override
public String promptSecret(String message)
{
if (isAcceptDefaultsEnabled())
{
return null;
}
PrintStream out = console.getShell().out();
out.print(message);
String output;
Expand All @@ -68,7 +80,17 @@ public String promptSecret(String message)
@Override
public boolean promptBoolean(String message)
{
if (isAcceptDefaultsEnabled())
{
return true;
}
return "Y".equalsIgnoreCase(prompt(message + " [y/N]"));
}

private boolean isAcceptDefaultsEnabled()
{
Object acceptDefaultsFlag = context.getAttributeMap().get("ACCEPT_DEFAULTS");
return acceptDefaultsFlag != null && "true".equalsIgnoreCase(acceptDefaultsFlag.toString());
}

}

0 comments on commit 076001a

Please sign in to comment.