package org.jboss.fresh.shell.commands;
import org.jboss.fresh.vfs.FileName;
import org.jboss.fresh.vfs.VFS;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.shell.AbstractExecutable;
import java.io.PrintWriter;
// EX OK
public class PosExe extends AbstractExecutable {
private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(PosExe.class);
/**
Sets the position of the first file specified right before the second file specified.
*/
public void process(String exename, String[] params) throws Exception {
log.debug("entered");
if (helpRequested()) {
PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
out.print("Usage: pos [--help] FILE NEXT\n");
out.print(" FILE : file to be moved.\n");
out.print(" NEXT : file coming right after FILE in the same directory.\n");
out.print(" --help : this help\n");
out.close();
log.debug("done");
return;
}
PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
VFS vfs = shell.getVFS();
FileName pwd = new FileName(shell.getEnvProperty("PWD"));
if (params.length == 2) {
FileName file = new FileName(params[0]);
FileName next = new FileName(params[1]);
if (file.isRelative())
file = pwd.absolutize(file);
if (next.isRelative())
next = pwd.absolutize(next);
if (vfs.exists(shell.getUserCtx(), file, true) && vfs.exists(shell.getUserCtx(), next, true)) {
vfs.moveBefore(shell.getUserCtx(), file, next);
}
} else if (params.length == 1) {
FileName file = new FileName(params[0]);
if (file.isRelative())
file = pwd.absolutize(file);
if (vfs.exists(shell.getUserCtx(), file, true))
vfs.moveBefore(shell.getUserCtx(), file, null);
}
out.close();
log.debug("done");
}
}