package org.ibex.xt.shell;
-import java.util.*;
-
+import java.io.StringReader;
import java.io.Writer;
import java.io.IOException;
+import java.util.*;
+
+import org.ibex.js.*;
+
public abstract class Command {
/** Returns the command name. */
public abstract String name();
public String help() { return "Print the path to the current object."; }
public void execute(Writer w, String[] c, Env env) throws IOException {
if (c.length != 1) { w.write(usage()); return; }
- w.write(env.path.equals("") ? "/" : env.path.replace('.', '/'));
+ w.write(env.path.equals("") ? "." : env.path);
w.write("\n");
}
}
public String help() { return
"Chnages the current object that all other commands use "+
"as the base for running.\n Pass either a relative path "+
- "(e.g. in /prevalent, type cd myob, now in /prevalent/myob) "+
- "or an absolute path (e.g. cd /prevalent/myob).\n\n" +
+ "(e.g. in .prevalent, type cd myob, now in .prevalent.myob) "+
+ "or an absolute path (e.g. cd .prevalent.myob).\n\n" +
"To go up one level, cd .. can be used.";
}
public void execute(Writer w, String[] c, Env env) throws IOException {
if (c.length > 2) w.write(usage());
- else if (c.length == 1 || c[1].equals("") || c[1].equals("/")) env.path = "";
+ else if (c.length == 1 || c[1].equals("") || c[1].equals(".")) env.path = "";
else if (c[1].equals("..")) {
String n = env.path;
n = n.substring(0, n.lastIndexOf('.'));
}
}
}
+ }
+ }
+
+ public static class Set extends Command {
+ public String name() { return "set"; }
+ public String usage() { return "[name] [object]"; }
+ public String summary() { return "Sets ."; }
+ public String help() { return "Removes objects."; } // FIXME
+
+ public void execute(Writer w, String[] c, Env env) throws IOException {
+ if (c.length < 3) { w.write(usage()); }
+
+ String m = c[1];
+ String s = "return (";
+ for (int i=2; i < c.length; i++) s += c[i];
+ s += ");";
+ JS js;
+ try { js = JS.fromReader("input", 0, new StringReader(s)); }
+ catch (IOException e) {
+ w.write("error: ");
+ w.write(e.getMessage());
+ w.write("\n");
+ return;
+ }
- // Object ret = send(new KeyRequest( FIXME: CompositeRequest
+ Request.Response ret = env.send(new Request.SetKey(env.path, m, js));
}
}
-
}