X-Git-Url: http://git.megacz.com/?p=org.ibex.xt-crawshaw.git;a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2Fshell%2FCommand.java;fp=src%2Fjava%2Forg%2Fibex%2Fxt%2Fshell%2FCommand.java;h=f5ad6fb3f6883955e333a25a5990bf377bd64bb5;hp=238f8af09f32b0221ff67bd066a3151c8013290c;hb=6430dcd3c8bf58a04a370614e375a74f5f2dce8b;hpb=fc9f528e7acb1baf7c145b22dd0b6469968aaec0 diff --git a/src/java/org/ibex/xt/shell/Command.java b/src/java/org/ibex/xt/shell/Command.java index 238f8af..f5ad6fb 100644 --- a/src/java/org/ibex/xt/shell/Command.java +++ b/src/java/org/ibex/xt/shell/Command.java @@ -1,10 +1,13 @@ 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(); @@ -97,7 +100,7 @@ public abstract class Command { 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"); } } @@ -109,13 +112,13 @@ public abstract class Command { 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('.')); @@ -177,11 +180,34 @@ public abstract class Command { } } } + } + } + + 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)); } } - }