SHL-41 - Improve error handling for command line options when staring shell

SHL-39 - Remove NAPA specific environment option, replce with Spring 3.1 profile support
This commit is contained in:
Mark Pollack
2012-07-12 14:34:31 -04:00
parent d825aaeb41
commit 9ceb0e8618

View File

@@ -34,21 +34,27 @@ public class SimpleShellCommandLineOptions {
int i = 0;
while (i < args.length) {
String arg = args[i++];
if (arg.equals("--environment")) {
String environment = args[i++];
options.extraSystemProperties.put("napa.application.profile", environment);
if (arg.equals("--profiles")) {
try {
String profiles = args[i++];
options.extraSystemProperties.put("spring.profiles.active", profiles);
} catch (ArrayIndexOutOfBoundsException e) {
LOGGER.warning("No value specified for --profiles option");
}
}
else if (arg.equals("--cmdfile")) {
File f = new File(args[i++]);
try {
File f = new File(args[i++]);
commands.addAll(FileUtils.readLines(f));
} catch (IOException e) {
LOGGER.warning("Could not read lines from command file: " + e.getMessage());
} catch (ArrayIndexOutOfBoundsException e) {
LOGGER.warning("No value specified for --cmdfile option");
}
}
else if (arg.equals("--histsize")) {
String histSizeArg = args[i++];
else if (arg.equals("--histsize")) {
try {
String histSizeArg = args[i++];
int histSize = Integer.parseInt(histSizeArg);
if (histSize <= 0) {
LOGGER.warning("histsize option must be > 0, using default value of " + DEFAULT_HISTORY_SIZE);
@@ -56,7 +62,9 @@ public class SimpleShellCommandLineOptions {
options.historySize = histSize;
}
} catch (NumberFormatException e) {
LOGGER.warning("Unable to parse histsize value [" + histSizeArg + "] to an integer ");
LOGGER.warning("Unable to parse histsize value to an integer ");
} catch (ArrayIndexOutOfBoundsException ae) {
LOGGER.warning("No value specified for --histsize option");
}
}
else if (arg.equals("--help")) {
@@ -92,7 +100,6 @@ public class SimpleShellCommandLineOptions {
}
private static void printUsage(){
System.out.println("Usage:");
System.out.println("java -jar {jarname} --help --histsize {size} --cmdfile {file}");
System.out.println("Usage: --help --histsize [size] --cmdfile [file name] --profiles [comma-separated list of profile names]");
}
}