Use ShellContextHolder to get variables
git-svn-id: https://svn.apache.org/repos/asf/geronimo/gshell/trunk@726177 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java b/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java
index cacd1a0..3370d26 100644
--- a/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java
+++ b/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/ConsolePrompterImpl.java
@@ -24,6 +24,7 @@
import org.apache.geronimo.gshell.command.Variables;
import org.apache.geronimo.gshell.console.Console;
import org.apache.geronimo.gshell.interpolation.VariablesValueSource;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
@@ -41,33 +42,29 @@
{
private final Logger log = LoggerFactory.getLogger(getClass());
- private final Application application;
-
private final Interpolator interp = new StringSearchInterpolator("%{", "}");
private final VariablesValueSource variablesValueSource = new VariablesValueSource();
private final AnsiRenderer renderer = new AnsiRenderer();
+ private final String defaultPrompt;
+
public ConsolePrompterImpl(final Application application) {
assert application != null;
- this.application = application;
- }
-
- // @PostConstruct
- public void init() {
- assert application != null;
+
interp.addValueSource(new PrefixedObjectValueSource("application", application));
interp.addValueSource(new PrefixedObjectValueSource("branding", application.getModel().getBranding()));
interp.addValueSource(variablesValueSource);
+
+ defaultPrompt = application.getModel().getBranding().getPrompt();
}
public String prompt() {
String prompt = null;
- assert application != null;
- Variables vars = application.getVariables();
- String pattern = (String) vars.get("gshell.prompt");
+ Variables vars = ShellContextHolder.get().getVariables();
+ String pattern = vars.get("gshell.prompt", String.class);
if (pattern != null) {
assert variablesValueSource != null;
@@ -84,7 +81,7 @@
// Use a default prompt if we don't have anything here
if (prompt == null) {
- prompt = defaultPrompt();
+ prompt = defaultPrompt;
}
// Encode ANSI muck if it looks like there are codes encoded
@@ -94,9 +91,4 @@
return prompt;
}
-
- private String defaultPrompt() {
- assert application != null;
- return application.getModel().getBranding().getName() + "> ";
- }
}
\ No newline at end of file