diff options
| author | Robert Greig <rgreig@apache.org> | 2007-04-04 15:18:44 +0000 |
|---|---|---|
| committer | Robert Greig <rgreig@apache.org> | 2007-04-04 15:18:44 +0000 |
| commit | 373ed42d849c7409d47ba1f4216b235dc2e233f4 (patch) | |
| tree | 6ad5a8946a7d34dac43f50b0184942f54a510a5e /java | |
| parent | 67d2bdda471640a68e12d63f5de471471057a193 (diff) | |
| download | qpid-python-373ed42d849c7409d47ba1f4216b235dc2e233f4.tar.gz | |
Added standard command line handline
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@525531 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
| -rw-r--r-- | java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java b/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java index 6173780aa7..9051d6b470 100644 --- a/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java +++ b/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java @@ -143,8 +143,8 @@ public class CommandLineParser String[] nextOptionSpec = config[i];
addOption(nextOptionSpec[0], nextOptionSpec[1], (nextOptionSpec.length > 2) ? nextOptionSpec[2] : null,
- (nextOptionSpec.length > 3) ? ("true".equals(nextOptionSpec[3]) ? true : false) : false,
- (nextOptionSpec.length > 4) ? nextOptionSpec[4] : null);
+ (nextOptionSpec.length > 3) ? ("true".equals(nextOptionSpec[3]) ? true : false) : false,
+ (nextOptionSpec.length > 4) ? nextOptionSpec[4] : null);
}
}
@@ -209,8 +209,9 @@ public class CommandLineParser // Print usage on each of the command line options.
for (CommandLineOption optionInfo : optionMap.values())
{
- result += optionInfo.option + " " + ((optionInfo.argument != null) ? (optionInfo.argument + " ") : "")
- + optionInfo.comment + "\n";
+ result +=
+ optionInfo.option + " " + ((optionInfo.argument != null) ? (optionInfo.argument + " ") : "")
+ + optionInfo.comment + "\n";
}
return result;
@@ -604,6 +605,37 @@ public class CommandLineParser }
/**
+ * Extracts all name=value pairs from the command line, sets them all as system properties and also returns
+ * a map of properties containing them.
+ *
+ * @param args The command line.
+ *
+ * @return A set of properties containing all name=value pairs from the command line.
+ */
+ public static Properties processCommandLine(String[] args, CommandLineParser commandLine)
+ {
+ // Capture the command line arguments or display errors and correct usage and then exit.
+ Properties options = null;
+
+ try
+ {
+ options = commandLine.parseCommandLine(args);
+
+ // Add all the trailing command line options (name=value pairs) to system properties. They may be picked up
+ // from there.
+ commandLine.addCommandLineToSysProperties();
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.out.println(commandLine.getErrors());
+ System.out.println(commandLine.getUsage());
+ System.exit(1);
+ }
+
+ return options;
+ }
+
+ /**
* Holds information about a command line options. This includes what its name is, whether or not it is a flag,
* whether or not it is mandatory, what its user comment is, what its argument reminder text is and what its
* regular expression format is.
@@ -646,7 +678,7 @@ public class CommandLineParser * @param formatRegexp The regular expression that the argument to this option must meet to be valid.
*/
public CommandLineOption(String option, boolean expectsArgs, String comment, String argument, boolean mandatory,
- String formatRegexp)
+ String formatRegexp)
{
this.option = option;
this.expectsArgs = expectsArgs;
|
