|
From: <ls...@us...> - 2011-07-31 13:46:40
|
Revision: 5840
http://jnode.svn.sourceforge.net/jnode/?rev=5840&view=rev
Author: lsantha
Date: 2011-07-31 13:46:34 +0000 (Sun, 31 Jul 2011)
Log Message:
-----------
Extended 'eject' command to load media with the '-t' option and to operate on the first removable media device when no device is specified.
Modified Paths:
--------------
trunk/fs/descriptors/org.jnode.fs.command.xml
trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java
Modified: trunk/fs/descriptors/org.jnode.fs.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.command.xml 2011-07-31 13:43:44 UTC (rev 5839)
+++ trunk/fs/descriptors/org.jnode.fs.command.xml 2011-07-31 13:46:34 UTC (rev 5840)
@@ -27,7 +27,10 @@
<extension point="org.jnode.shell.syntaxes">
<syntax alias="eject">
- <argument argLabel="device" description="eject a device with a removable medium"/>
+ <sequence>
+ <optional><option argLabel="t" shortName="t" description="load a device with a removable medium"/></optional>
+ <optional><argument argLabel="device" description="eject a device with a removable medium"/></optional>
+ </sequence>
</syntax>
<syntax alias="mount">
<empty description="list all mounted filesystems"/>
Modified: trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2011-07-31 13:43:44 UTC (rev 5839)
+++ trunk/fs/src/fs/org/jnode/fs/command/EjectCommand.java 2011-07-31 13:46:34 UTC (rev 5840)
@@ -22,39 +22,65 @@
import java.io.IOException;
+import java.util.Iterator;
import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.Device;
+import org.jnode.driver.DeviceUtils;
import org.jnode.driver.RemovableDeviceAPI;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.DeviceArgument;
+import org.jnode.shell.syntax.FlagArgument;
-
/**
* @author Ewout Prangsma (ep...@us...)
+ * @author Levente S\u00e1ntha
*/
public class EjectCommand extends AbstractCommand {
private static final String help_device = "Device to eject the medium from";
+ private static final String help_load = "Load the medium into the device";
private static final String fmt_failed = "Eject failed for %s: %s";
- private final DeviceArgument argDevice
- = new DeviceArgument("device", Argument.MANDATORY | Argument.EXISTING, help_device, RemovableDeviceAPI.class);
+ private final DeviceArgument argDevice = new DeviceArgument("device", Argument.OPTIONAL | Argument.EXISTING,
+ help_device, RemovableDeviceAPI.class);
+ private final FlagArgument argLoad = new FlagArgument("t", Argument.OPTIONAL, help_load);
public EjectCommand() {
super("Eject the medium from a given device");
- registerArguments(argDevice);
+ registerArguments(argLoad, argDevice);
}
public static void main(String[] args) throws Exception {
new EjectCommand().execute(args);
}
- public void execute()
- throws ApiNotFoundException, IOException {
- final Device dev = argDevice.getValue();
+ public void execute() throws ApiNotFoundException, IOException {
+ final Device dev;
+ if (!argDevice.isSet()) {
+ Iterator<Device> iter = DeviceUtils.getDevicesByAPI(RemovableDeviceAPI.class).iterator();
+ dev = iter.hasNext() ? iter.next() : null;
+ } else {
+ dev = argDevice.getValue();
+ }
+
+ if (dev == null) {
+ getError().getPrintWriter().println("No removable device found.");
+ return;
+ }
+
final RemovableDeviceAPI api = dev.getAPI(RemovableDeviceAPI.class);
try {
- api.eject();
+ if (!api.canEject()) {
+ getError().getPrintWriter().format("No device found to %s.",
+ argLoad.isSet() ? "load" : "eject");
+ return;
+ }
+
+ if (argLoad.isSet()) {
+ api.load();
+ } else {
+ api.eject();
+ }
} catch (IOException ex) {
getError().getPrintWriter().format(fmt_failed, dev.getId(), ex.getLocalizedMessage());
exit(1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|