You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/28 16:30:47 UTC
svn commit: r699823 - in
/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main:
java/org/apache/geronimo/gshell/commands/builtins/SetAction.java
resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties
Author: jdillon
Date: Sun Sep 28 07:30:47 2008
New Revision: 699823
URL: http://svn.apache.org/viewvc?rev=699823&view=rev
Log:
Added --verbose flag, which when enabled will show more details about defined variables
Modified:
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetAction.java
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetAction.java?rev=699823&r1=699822&r2=699823&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetAction.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/SetAction.java Sun Sep 28 07:30:47 2008
@@ -51,52 +51,75 @@
@Option(name="-m", aliases={"--mode"})
private Mode mode = Mode.VARIABLE;
+ @Option(name="-v", aliases={"--verbose"})
+ private boolean verbose;
+
@Argument
private List<String> args = null;
public Object execute(final CommandContext context) throws Exception {
assert context != null;
- IO io = context.getIo();
- Variables variables = context.getVariables();
-
// No args... list all properties or variables
if (args == null || args.size() == 0) {
- switch (mode) {
- case PROPERTY: {
- Properties props = System.getProperties();
+ return displayList(context);
+ }
- for (Object o : props.keySet()) {
- String name = (String) o;
- String value = props.getProperty(name);
-
- io.out.print(name);
- io.out.print("=");
- io.out.print(value);
- io.out.println();
- }
- break;
- }
+ return set(context);
+ }
+
+ private Object displayList(final CommandContext context) throws Exception {
+ assert context != null;
+ IO io = context.getIo();
- case VARIABLE: {
- Iterator<String> iter = variables.names();
+ switch (mode) {
+ case PROPERTY: {
+ Properties props = System.getProperties();
+
+ for (Object o : props.keySet()) {
+ String name = (String) o;
+ String value = props.getProperty(name);
+
+ io.out.print(name);
+ io.out.print("=");
+ io.out.print(value);
+ // Value is always a string, so no need to add muck here for --verbose
- while (iter.hasNext()) {
- String name = iter.next();
- Object value = variables.get(name);
-
- io.out.print(name);
- io.out.print("=");
- io.out.print(value);
- io.out.println();
- }
- break;
+ io.out.println();
}
+ break;
}
- return Result.SUCCESS;
+ case VARIABLE: {
+ Variables variables = context.getVariables();
+ Iterator<String> iter = variables.names();
+
+ while (iter.hasNext()) {
+ String name = iter.next();
+ Object value = variables.get(name);
+
+ io.out.print(name);
+ io.out.print("=");
+ io.out.print(value);
+
+ // When --verbose include the class details of the value
+ if (verbose && value != null) {
+ io.out.print(" (");
+ io.out.print(value.getClass());
+ io.out.print(")");
+ }
+
+ io.out.println();
+ }
+ break;
+ }
}
+ return Result.SUCCESS;
+ }
+
+ private Object set(final CommandContext context) throws Exception {
+ assert context != null;
//
// FIXME: This does not jive well with the parser, and stuff like foo = "b a r"
//
@@ -114,6 +137,7 @@
break;
case VARIABLE:
+ Variables variables = context.getVariables();
setVariable(variables, namevalue);
break;
}
@@ -139,11 +163,11 @@
nv.name = input;
nv.value = "true";
}
- else if ( firstDoubleQuote != -1) {
+ else if (firstDoubleQuote != -1) {
nv.name = input.substring(0,i);
nv.value = input.substring(firstDoubleQuote + 1, input.length()-1);
}
- else if ( firstSingleQuote != -1) {
+ else if (firstSingleQuote != -1) {
nv.name = input.substring(0,i);
nv.value = input.substring(firstSingleQuote + 1, input.length()-1);
}
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties?rev=699823&r1=699822&r2=699823&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/SetAction.properties Sun Sep 28 07:30:47 2008
@@ -27,6 +27,8 @@
command.option.mode=Set mode
+command.option.verbose=Enable verbose output
+
command.argument.args=Variable definition
command.manual=\