From 67fe39c9b91686bb1a8d2fc5feaf5de096061a58 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Tue, 04 Feb 2014 13:51:34 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1303 Split out CLI support from opendj-ldap-toolkit into a separate Maven module, "opendj-cli" - Added SubCommand && SubCommandParser. - Added more commonsArguments. - Replaced "double" in IntegerArgument to "int". - Added LINE_SEPARATOR in Utils. - Updated Constants. - Updated messages.
---
opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
index 0b1a392..264ead1 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -44,6 +44,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.SortedSet;
@@ -62,7 +63,7 @@
* file to obtain default values for arguments there if they are not specified
* on the command-line.
*/
-public final class ArgumentParser {
+public class ArgumentParser {
/**
* The argument that will be used to indicate the file properties.
*/
@@ -143,7 +144,7 @@
private String[] rawArguments;
/** Set of argument groups. */
- private Set<ArgumentGroup> argumentGroups;
+ protected Set<ArgumentGroup> argumentGroups;
/**
* Group for arguments that have not been explicitly grouped. These will
@@ -1593,4 +1594,41 @@
buffer.append(EOL);
}
}
+
+ void normalizeArguments(final Properties argumentProperties, final List<Argument> arguments)
+ throws ArgumentException {
+ for (final Argument a : arguments) {
+ if (!a.isPresent()
+ // See if there is a value in the properties that can be used
+ && argumentProperties != null && a.getPropertyName() != null) {
+ final String value = argumentProperties.getProperty(a.getPropertyName().toLowerCase());
+ final LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
+ if (value != null) {
+ Boolean addValue = true;
+ if (!(a instanceof BooleanArgument)) {
+ addValue = a.valueIsAcceptable(value, invalidReason);
+ }
+ if (addValue) {
+ a.addValue(value);
+ if (a.needsValue()) {
+ a.setPresent(true);
+ }
+ a.setValueSetByProperty(true);
+ }
+ }
+ }
+
+ if (!a.isPresent() && a.needsValue()) {
+ // See if the argument defines a default.
+ if (a.getDefaultValue() != null) {
+ a.addValue(a.getDefaultValue());
+ }
+
+ // If there is still no value and the argument is required, then that's a problem.
+ if (!a.hasValue() && a.isRequired()) {
+ throw new ArgumentException(ERR_ARGPARSER_NO_VALUE_FOR_REQUIRED_ARG.get(a.getName()));
+ }
+ }
+ }
+ }
}
--
Gitblit v1.10.0