+ w.write("\n");
+ }
+ }
+
+ public class CdCommand extends Command {
+ public String name() { return "cd"; }
+ public String usage() { return "[path]"; }
+ public String summary() { return "Change current object."; }
+ 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" +
+ "To go up one level, cd .. can be used.";
+ }
+ public void execute(Writer w, String[] c) throws IOException {
+ if (c.length > 2) w.write(usage());
+ else if (c.length == 1 || c[1].equals("") || c[1].equals("/")) pwd = ".";
+ else if (c[1].equals("..")) {
+ String n = pwd.substring(0, pwd.lastIndexOf('.'));
+ pwd = n.equals("") ? "." : n;
+ } else {
+ String n = path(c[1]);
+ Object ret = send(new KeyRequest(n));
+
+ if (ret == null) {
+ w.write("error: (unexpected) server returned null\n");
+ } else if (ret instanceof List && ((List)ret).size() == 1) {
+ pwd = n;
+ } else if (ret instanceof JSExn ||
+ (ret instanceof List && ((List)ret).size() == 0)) {
+ w.write("cd ");
+ w.write(c[1]);
+ w.write(": no such path\n");
+ } else {
+ w.write("error: (unexpected) server returned ");
+ w.write(ret.toString());
+ w.write("\n");
+ }
+ }
+ }
+ }
+
+ public class RmCommand extends Command {
+ public String name() { return "rm"; }
+ public String usage() { return "[options] [path]"; }
+ public String summary() { return "Removes objects."; }
+ public String help() { return "Removes objects."; } // FIXME
+ public void execute(Writer w, String[] c) throws IOException {
+ if (c.length == 1) { w.write(usage()); }
+
+ String[] r = new String[c.length - 1];
+ for (int i=0; i < r.length; i++) r[i] = path(c[i + 1]);
+ // Object ret = send(new KeyRequest( FIXME: CompositeRequest