added platform configuration argument.

This commit is contained in:
nvt-se 2009-08-13 12:11:20 +00:00
parent 0798c56899
commit 9ab5859421
2 changed files with 43 additions and 34 deletions

View file

@ -8,10 +8,12 @@ Building:
Usage: Usage:
java -jar coffee.jar [-i|e|r <file>] [-l|s] <file system image> java -jar coffee.jar [-p <platform>] [-i|e|r <file>] [-l|s] <file system image>
Options: Options:
-p Selects the platform configuration of Coffee to use.
Valid choices: sky (default), esb.
-i Inserts a new file into the file system. -i Inserts a new file into the file system.
-e Extracts a file from the file system and saves it locally. -e Extracts a file from the file system and saves it locally.
-r Removes a file from the file system. -r Removes a file from the file system.

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: CoffeeManager.java,v 1.4 2009/08/11 17:03:59 fros4943 Exp $ * $Id: CoffeeManager.java,v 1.5 2009/08/13 12:11:20 nvt-se Exp $
* *
* @author Nicolas Tsiftes * @author Nicolas Tsiftes
* *
@ -41,6 +41,8 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import se.sics.coffee.CoffeeFS.CoffeeException;
import se.sics.coffee.CoffeeFS.CoffeeFileException;
public class CoffeeManager { public class CoffeeManager {
private static CoffeeFS coffeeFS; private static CoffeeFS coffeeFS;
@ -53,50 +55,51 @@ public class CoffeeManager {
String filename = ""; String filename = "";
String fsImage = ""; String fsImage = "";
usage += "[-p <hardware platform>] ";
usage += "[-i|e|r <file>] "; usage += "[-i|e|r <file>] ";
usage += "[-l|s] "; usage += "[-l|s] ";
usage += "<file system image>"; usage += "<file system image>";
if (args.length < 1) { if (args.length < 2) {
System.err.println(usage); System.err.println(usage);
System.exit(1); System.exit(1);
} }
if (args.length > 1) { Pattern optionArg = Pattern.compile("-(p|i|e|r)");
Pattern validArg = Pattern.compile("-(i|e|r|l|s)");
Matcher m = validArg.matcher(args[0]); for(int i = 0; i < args.length - 1; i++) {
if (!m.matches()) { if (optionArg.matcher(args[i]).matches()) {
if(i >= args.length - 2) {
System.err.println(usage); System.err.println(usage);
System.exit(1); System.exit(1);
} }
}
if (args[0].equals("-i") || args[0].equals("-e") || args[0].equals("-r")) { if(args[i].equals("-p")) {
if (args.length != 3) { platform = args[i + 1];
System.err.println(usage); i++;
System.exit(1); } else if (args[i].equals("-i")) {
}
if (args[0].equals("-i")) {
command = Command.INSERT; command = Command.INSERT;
} else if (args[0].equals("-r")) { filename = args[i + 1];
i++;
} else if (args[i].equals("-r")) {
command = Command.REMOVE; command = Command.REMOVE;
} else { filename = args[i + 1];
i++;
} else if (args[i].equals("-i")) {
command = Command.EXTRACT; command = Command.EXTRACT;
} filename = args[i + 1];
filename = args[1]; i++;
fsImage = args[2]; } else if (args[i].equals("-l")) {
command = Command.LIST;
} else if (args[i].equals("-s")) {
command = Command.STATS;
} else { } else {
if (args.length != 2) {
System.err.println(usage); System.err.println(usage);
System.exit(1); System.exit(1);
} }
if (args[0].equals("-l")) {
command = Command.LIST;
} else {
command = Command.STATS;
}
fsImage = args[1];
}
} }
fsImage = args[args.length - 1];
try { try {
CoffeeConfiguration conf = new CoffeeConfiguration(platform + ".properties"); CoffeeConfiguration conf = new CoffeeConfiguration(platform + ".properties");
@ -141,6 +144,10 @@ public class CoffeeManager {
} }
} catch (IOException e) { } catch (IOException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} catch (CoffeeException e) {
System.err.println(e.getMessage());
} catch (CoffeeFileException e) {
System.err.println(e.getMessage());
} }
} }