use of com.unboundid.util.args.SubCommand in project ldapsdk by pingidentity.
the class ManageAccount method createSubCommand.
/**
* Creates a subcommand with the provided information.
*
* @param subcommandType The subcommand type.
* @param subcommandParser The argument parser for the subcommand-specific
* arguments.
* @param examples The example usages for the subcommand.
*
* @throws ArgumentException If a problem is encountered while creating the
* subcommand.
*/
private void createSubCommand(@NotNull final ManageAccountSubCommandType subcommandType, @NotNull final ArgumentParser subcommandParser, @NotNull final LinkedHashMap<String[], String> examples) throws ArgumentException {
final SubCommand subCommand = new SubCommand(subcommandType.getPrimaryName(), subcommandType.getDescription(), subcommandParser, examples);
for (final String alternateName : subcommandType.getAlternateNames()) {
subCommand.addName(alternateName, true);
}
parser.addSubCommand(subCommand);
}
use of com.unboundid.util.args.SubCommand in project ldapsdk by pingidentity.
the class ManageAccountProcessor method createPasswordPolicyStateOperation.
/**
* Creates the password policy state operation that will be processed against
* all target entries.
*
* @param commandBuffer The buffer to which the manage-account command line
* should be appended.
*
* @return The password policy state operation that was created.
*
* @throws LDAPException If a problem is encountered while creating the
* password policy state operation.
*/
@NotNull()
private PasswordPolicyStateOperation createPasswordPolicyStateOperation(@NotNull final StringBuilder commandBuffer) throws LDAPException {
final SubCommand subcommand = parser.getSelectedSubCommand();
if (subcommand == null) {
// This should never happen.
throw new LDAPException(ResultCode.PARAM_ERROR, ERR_MANAGE_ACCT_PROCESSOR_NO_SUBCOMMAND.get(manageAccount.getToolName()));
}
final ManageAccountSubCommandType subcommandType = ManageAccountSubCommandType.forName(subcommand.getPrimaryName());
if (subcommandType == null) {
// This should also never happen.
throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_MANAGE_ACCT_PROCESSOR_UNSUPPORTED_SUBCOMMAND.get(subcommand.getPrimaryName(), manageAccount.getToolName()));
}
commandBuffer.append(manageAccount.getToolName());
commandBuffer.append(' ');
commandBuffer.append(subcommandType.getPrimaryName());
switch(subcommandType) {
case GET_ALL:
// extended request without any operations.
return null;
case GET_PASSWORD_POLICY_DN:
return PasswordPolicyStateOperation.createGetPasswordPolicyDNOperation();
case GET_ACCOUNT_IS_USABLE:
return PasswordPolicyStateOperation.createGetAccountIsUsableOperation();
case GET_ACCOUNT_USABILITY_NOTICES:
return PasswordPolicyStateOperation.createGetAccountUsabilityNoticesOperation();
case GET_ACCOUNT_USABILITY_WARNINGS:
return PasswordPolicyStateOperation.createGetAccountUsabilityWarningsOperation();
case GET_ACCOUNT_USABILITY_ERRORS:
return PasswordPolicyStateOperation.createGetAccountUsabilityErrorsOperation();
case GET_PASSWORD_CHANGED_TIME:
return PasswordPolicyStateOperation.createGetPasswordChangedTimeOperation();
case SET_PASSWORD_CHANGED_TIME:
return PasswordPolicyStateOperation.createSetPasswordChangedTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_PASSWORD_CHANGED_TIME:
return PasswordPolicyStateOperation.createClearPasswordChangedTimeOperation();
case GET_ACCOUNT_IS_DISABLED:
return PasswordPolicyStateOperation.createGetAccountDisabledStateOperation();
case SET_ACCOUNT_IS_DISABLED:
return PasswordPolicyStateOperation.createSetAccountDisabledStateOperation(getBoolean(subcommand, commandBuffer));
case CLEAR_ACCOUNT_IS_DISABLED:
return PasswordPolicyStateOperation.createClearAccountDisabledStateOperation();
case GET_ACCOUNT_ACTIVATION_TIME:
return PasswordPolicyStateOperation.createGetAccountActivationTimeOperation();
case SET_ACCOUNT_ACTIVATION_TIME:
return PasswordPolicyStateOperation.createSetAccountActivationTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_ACCOUNT_ACTIVATION_TIME:
return PasswordPolicyStateOperation.createClearAccountActivationTimeOperation();
case GET_SECONDS_UNTIL_ACCOUNT_ACTIVATION:
return PasswordPolicyStateOperation.createGetSecondsUntilAccountActivationOperation();
case GET_ACCOUNT_IS_NOT_YET_ACTIVE:
return PasswordPolicyStateOperation.createGetAccountIsNotYetActiveOperation();
case GET_ACCOUNT_EXPIRATION_TIME:
return PasswordPolicyStateOperation.createGetAccountExpirationTimeOperation();
case SET_ACCOUNT_EXPIRATION_TIME:
return PasswordPolicyStateOperation.createSetAccountExpirationTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_ACCOUNT_EXPIRATION_TIME:
return PasswordPolicyStateOperation.createClearAccountExpirationTimeOperation();
case GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION:
return PasswordPolicyStateOperation.createGetSecondsUntilAccountExpirationOperation();
case GET_ACCOUNT_IS_EXPIRED:
return PasswordPolicyStateOperation.createGetAccountIsExpiredOperation();
case GET_PASSWORD_EXPIRATION_WARNED_TIME:
return PasswordPolicyStateOperation.createGetPasswordExpirationWarnedTimeOperation();
case SET_PASSWORD_EXPIRATION_WARNED_TIME:
return PasswordPolicyStateOperation.createSetPasswordExpirationWarnedTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_PASSWORD_EXPIRATION_WARNED_TIME:
return PasswordPolicyStateOperation.createClearPasswordExpirationWarnedTimeOperation();
case GET_SECONDS_UNTIL_PASSWORD_EXPIRATION_WARNING:
return PasswordPolicyStateOperation.createGetSecondsUntilPasswordExpirationWarningOperation();
case GET_PASSWORD_EXPIRATION_TIME:
return PasswordPolicyStateOperation.createGetPasswordExpirationTimeOperation();
case GET_SECONDS_UNTIL_PASSWORD_EXPIRATION:
return PasswordPolicyStateOperation.createGetSecondsUntilPasswordExpirationOperation();
case GET_PASSWORD_IS_EXPIRED:
return PasswordPolicyStateOperation.createGetPasswordIsExpiredOperation();
case GET_ACCOUNT_IS_FAILURE_LOCKED:
return PasswordPolicyStateOperation.createGetAccountIsFailureLockedOperation();
case SET_ACCOUNT_IS_FAILURE_LOCKED:
return PasswordPolicyStateOperation.createSetAccountIsFailureLockedOperation(getBoolean(subcommand, commandBuffer));
case GET_FAILURE_LOCKOUT_TIME:
return PasswordPolicyStateOperation.createGetFailureLockoutTimeOperation();
case GET_SECONDS_UNTIL_AUTHENTICATION_FAILURE_UNLOCK:
return PasswordPolicyStateOperation.createGetSecondsUntilAuthenticationFailureUnlockOperation();
case GET_AUTHENTICATION_FAILURE_TIMES:
return PasswordPolicyStateOperation.createGetAuthenticationFailureTimesOperation();
case ADD_AUTHENTICATION_FAILURE_TIME:
return PasswordPolicyStateOperation.createAddAuthenticationFailureTimeOperation(getDates(subcommand, commandBuffer));
case SET_AUTHENTICATION_FAILURE_TIMES:
return PasswordPolicyStateOperation.createSetAuthenticationFailureTimesOperation(getDates(subcommand, commandBuffer));
case CLEAR_AUTHENTICATION_FAILURE_TIMES:
return PasswordPolicyStateOperation.createClearAuthenticationFailureTimesOperation();
case GET_REMAINING_AUTHENTICATION_FAILURE_COUNT:
return PasswordPolicyStateOperation.createGetRemainingAuthenticationFailureCountOperation();
case GET_ACCOUNT_IS_IDLE_LOCKED:
return PasswordPolicyStateOperation.createGetAccountIsIdleLockedOperation();
case GET_SECONDS_UNTIL_IDLE_LOCKOUT:
return PasswordPolicyStateOperation.createGetSecondsUntilIdleLockoutOperation();
case GET_IDLE_LOCKOUT_TIME:
return PasswordPolicyStateOperation.createGetIdleLockoutTimeOperation();
case GET_MUST_CHANGE_PASSWORD:
return PasswordPolicyStateOperation.createGetPasswordResetStateOperation();
case SET_MUST_CHANGE_PASSWORD:
return PasswordPolicyStateOperation.createSetPasswordResetStateOperation(getBoolean(subcommand, commandBuffer));
case CLEAR_MUST_CHANGE_PASSWORD:
return PasswordPolicyStateOperation.createClearPasswordResetStateOperation();
case GET_ACCOUNT_IS_PASSWORD_RESET_LOCKED:
return PasswordPolicyStateOperation.createGetAccountIsResetLockedOperation();
case GET_SECONDS_UNTIL_PASSWORD_RESET_LOCKOUT:
return PasswordPolicyStateOperation.createGetSecondsUntilPasswordResetLockoutOperation();
case GET_PASSWORD_RESET_LOCKOUT_TIME:
return PasswordPolicyStateOperation.createGetResetLockoutTimeOperation();
case GET_LAST_LOGIN_TIME:
return PasswordPolicyStateOperation.createGetLastLoginTimeOperation();
case SET_LAST_LOGIN_TIME:
return PasswordPolicyStateOperation.createSetLastLoginTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_LAST_LOGIN_TIME:
return PasswordPolicyStateOperation.createClearLastLoginTimeOperation();
case GET_LAST_LOGIN_IP_ADDRESS:
return PasswordPolicyStateOperation.createGetLastLoginIPAddressOperation();
case SET_LAST_LOGIN_IP_ADDRESS:
return PasswordPolicyStateOperation.createSetLastLoginIPAddressOperation(getString(subcommand, commandBuffer));
case CLEAR_LAST_LOGIN_IP_ADDRESS:
return PasswordPolicyStateOperation.createClearLastLoginIPAddressOperation();
case GET_GRACE_LOGIN_USE_TIMES:
return PasswordPolicyStateOperation.createGetGraceLoginUseTimesOperation();
case ADD_GRACE_LOGIN_USE_TIME:
return PasswordPolicyStateOperation.createAddGraceLoginUseTimeOperation(getDates(subcommand, commandBuffer));
case SET_GRACE_LOGIN_USE_TIMES:
return PasswordPolicyStateOperation.createSetGraceLoginUseTimesOperation(getDates(subcommand, commandBuffer));
case CLEAR_GRACE_LOGIN_USE_TIMES:
return PasswordPolicyStateOperation.createClearGraceLoginUseTimesOperation();
case GET_REMAINING_GRACE_LOGIN_COUNT:
return PasswordPolicyStateOperation.createGetRemainingGraceLoginCountOperation();
case GET_PASSWORD_CHANGED_BY_REQUIRED_TIME:
return PasswordPolicyStateOperation.createGetPasswordChangedByRequiredTimeOperation();
case SET_PASSWORD_CHANGED_BY_REQUIRED_TIME:
return PasswordPolicyStateOperation.createSetPasswordChangedByRequiredTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_PASSWORD_CHANGED_BY_REQUIRED_TIME:
return PasswordPolicyStateOperation.createClearPasswordChangedByRequiredTimeOperation();
case GET_SECONDS_UNTIL_REQUIRED_PASSWORD_CHANGE_TIME:
return PasswordPolicyStateOperation.createGetSecondsUntilRequiredChangeTimeOperation();
case GET_PASSWORD_HISTORY_COUNT:
return PasswordPolicyStateOperation.createGetPasswordHistoryCountOperation();
case CLEAR_PASSWORD_HISTORY:
return PasswordPolicyStateOperation.createClearPasswordHistoryOperation();
case GET_HAS_RETIRED_PASSWORD:
return PasswordPolicyStateOperation.createHasRetiredPasswordOperation();
case GET_PASSWORD_RETIRED_TIME:
return PasswordPolicyStateOperation.createGetPasswordRetiredTimeOperation();
case GET_RETIRED_PASSWORD_EXPIRATION_TIME:
return PasswordPolicyStateOperation.createGetRetiredPasswordExpirationTimeOperation();
case CLEAR_RETIRED_PASSWORD:
return PasswordPolicyStateOperation.createPurgeRetiredPasswordOperation();
case GET_AVAILABLE_SASL_MECHANISMS:
return PasswordPolicyStateOperation.createGetAvailableSASLMechanismsOperation();
case GET_AVAILABLE_OTP_DELIVERY_MECHANISMS:
return PasswordPolicyStateOperation.createGetAvailableOTPDeliveryMechanismsOperation();
case GET_HAS_TOTP_SHARED_SECRET:
return PasswordPolicyStateOperation.createHasTOTPSharedSecretOperation();
case ADD_TOTP_SHARED_SECRET:
return PasswordPolicyStateOperation.createAddTOTPSharedSecretOperation(getStrings(subcommand, commandBuffer));
case REMOVE_TOTP_SHARED_SECRET:
return PasswordPolicyStateOperation.createRemoveTOTPSharedSecretOperation(getStrings(subcommand, commandBuffer));
case SET_TOTP_SHARED_SECRETS:
return PasswordPolicyStateOperation.createSetTOTPSharedSecretsOperation(getStrings(subcommand, commandBuffer));
case CLEAR_TOTP_SHARED_SECRETS:
return PasswordPolicyStateOperation.createClearTOTPSharedSecretsOperation();
case GET_HAS_REGISTERED_YUBIKEY_PUBLIC_ID:
return PasswordPolicyStateOperation.createHasYubiKeyPublicIDOperation();
case GET_REGISTERED_YUBIKEY_PUBLIC_IDS:
return PasswordPolicyStateOperation.createGetRegisteredYubiKeyPublicIDsOperation();
case ADD_REGISTERED_YUBIKEY_PUBLIC_ID:
return PasswordPolicyStateOperation.createAddRegisteredYubiKeyPublicIDOperation(getStrings(subcommand, commandBuffer));
case REMOVE_REGISTERED_YUBIKEY_PUBLIC_ID:
return PasswordPolicyStateOperation.createRemoveRegisteredYubiKeyPublicIDOperation(getStrings(subcommand, commandBuffer));
case SET_REGISTERED_YUBIKEY_PUBLIC_IDS:
return PasswordPolicyStateOperation.createSetRegisteredYubiKeyPublicIDsOperation(getStrings(subcommand, commandBuffer));
case CLEAR_REGISTERED_YUBIKEY_PUBLIC_IDS:
return PasswordPolicyStateOperation.createClearRegisteredYubiKeyPublicIDsOperation();
case GET_HAS_STATIC_PASSWORD:
return PasswordPolicyStateOperation.createHasStaticPasswordOperation();
case GET_LAST_BIND_PASSWORD_VALIDATION_TIME:
return PasswordPolicyStateOperation.createGetLastBindPasswordValidationTimeOperation();
case GET_SECONDS_SINCE_LAST_BIND_PASSWORD_VALIDATION:
return PasswordPolicyStateOperation.createGetSecondsSinceLastBindPasswordValidationOperation();
case SET_LAST_BIND_PASSWORD_VALIDATION_TIME:
return PasswordPolicyStateOperation.createSetLastBindPasswordValidationTimeOperation(getDate(subcommand, commandBuffer));
case CLEAR_LAST_BIND_PASSWORD_VALIDATION_TIME:
return PasswordPolicyStateOperation.createClearLastBindPasswordValidationTimeOperation();
case GET_ACCOUNT_IS_VALIDATION_LOCKED:
return PasswordPolicyStateOperation.createGetAccountIsValidationLockedOperation();
case SET_ACCOUNT_IS_VALIDATION_LOCKED:
return PasswordPolicyStateOperation.createSetAccountIsValidationLockedOperation(getBoolean(subcommand, commandBuffer));
case GET_RECENT_LOGIN_HISTORY:
return PasswordPolicyStateOperation.createGetRecentLoginHistoryOperation();
case CLEAR_RECENT_LOGIN_HISTORY:
return PasswordPolicyStateOperation.createClearRecentLoginHistoryOperation();
default:
// This should never happen.
throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_MANAGE_ACCT_PROCESSOR_UNSUPPORTED_SUBCOMMAND.get(subcommand.getPrimaryName(), manageAccount.getToolName()));
}
}
use of com.unboundid.util.args.SubCommand in project ldapsdk by pingidentity.
the class Base64Tool method addToolArguments.
/**
* Adds the command-line arguments supported for use with this tool to the
* provided argument parser. The tool may need to retain references to the
* arguments (and/or the argument parser, if trailing arguments are allowed)
* to it in order to obtain their values for use in later processing.
*
* @param parser The argument parser to which the arguments are to be added.
*
* @throws ArgumentException If a problem occurs while adding any of the
* tool-specific arguments to the provided
* argument parser.
*/
@Override()
public void addToolArguments(@NotNull final ArgumentParser parser) throws ArgumentException {
this.parser = parser;
// Create the subcommand for encoding data.
final ArgumentParser encodeParser = new ArgumentParser("encode", "Base64-encodes raw data.");
final StringArgument encodeDataArgument = new StringArgument('d', ARG_NAME_DATA, false, 1, "{data}", "The raw data to be encoded. If neither the --" + ARG_NAME_DATA + " nor the --" + ARG_NAME_INPUT_FILE + " argument is provided, " + "then the data will be read from standard input.");
encodeDataArgument.addLongIdentifier("rawData", true);
encodeDataArgument.addLongIdentifier("raw-data", true);
encodeParser.addArgument(encodeDataArgument);
final FileArgument encodeDataFileArgument = new FileArgument('f', ARG_NAME_INPUT_FILE, false, 1, null, "The path to a file containing the raw data to be encoded. If " + "neither the --" + ARG_NAME_DATA + " nor the --" + ARG_NAME_INPUT_FILE + " argument is provided, then the data " + "will be read from standard input.", true, true, true, false);
encodeDataFileArgument.addLongIdentifier("rawDataFile", true);
encodeDataFileArgument.addLongIdentifier("input-file", true);
encodeDataFileArgument.addLongIdentifier("raw-data-file", true);
encodeParser.addArgument(encodeDataFileArgument);
final FileArgument encodeOutputFileArgument = new FileArgument('o', ARG_NAME_OUTPUT_FILE, false, 1, null, "The path to a file to which the encoded data should be written. " + "If this is not provided, the encoded data will be written to " + "standard output.", false, true, true, false);
encodeOutputFileArgument.addLongIdentifier("toEncodedFile", true);
encodeOutputFileArgument.addLongIdentifier("output-file", true);
encodeOutputFileArgument.addLongIdentifier("to-encoded-file", true);
encodeParser.addArgument(encodeOutputFileArgument);
final BooleanArgument encodeURLArgument = new BooleanArgument(null, ARG_NAME_URL, "Encode the data with the base64url mechanism rather than the " + "standard base64 mechanism.");
encodeParser.addArgument(encodeURLArgument);
final BooleanArgument encodeIgnoreTrailingEOLArgument = new BooleanArgument(null, ARG_NAME_IGNORE_TRAILING_LINE_BREAK, "Ignore any end-of-line marker that may be present at the end of " + "the data to encode.");
encodeIgnoreTrailingEOLArgument.addLongIdentifier("ignore-trailing-line-break", true);
encodeParser.addArgument(encodeIgnoreTrailingEOLArgument);
encodeParser.addExclusiveArgumentSet(encodeDataArgument, encodeDataFileArgument);
final LinkedHashMap<String[], String> encodeExamples = new LinkedHashMap<>(StaticUtils.computeMapCapacity(3));
encodeExamples.put(new String[] { "encode", "--data", "Hello" }, "Base64-encodes the string 'Hello' and writes the result to " + "standard output.");
encodeExamples.put(new String[] { "encode", "--inputFile", "raw-data.txt", "--outputFile", "encoded-data.txt" }, "Base64-encodes the data contained in the 'raw-data.txt' file and " + "writes the result to the 'encoded-data.txt' file.");
encodeExamples.put(new String[] { "encode" }, "Base64-encodes data read from standard input and writes the result " + "to standard output.");
final SubCommand encodeSubCommand = new SubCommand(SUBCOMMAND_NAME_ENCODE, "Base64-encodes raw data.", encodeParser, encodeExamples);
parser.addSubCommand(encodeSubCommand);
// Create the subcommand for decoding data.
final ArgumentParser decodeParser = new ArgumentParser("decode", "Decodes base64-encoded data.");
final StringArgument decodeDataArgument = new StringArgument('d', ARG_NAME_DATA, false, 1, "{data}", "The base64-encoded data to be decoded. If neither the --" + ARG_NAME_DATA + " nor the --" + ARG_NAME_INPUT_FILE + " argument is provided, then the data will be read from " + "standard input.");
decodeDataArgument.addLongIdentifier("encodedData", true);
decodeDataArgument.addLongIdentifier("encoded-data", true);
decodeParser.addArgument(decodeDataArgument);
final FileArgument decodeDataFileArgument = new FileArgument('f', ARG_NAME_INPUT_FILE, false, 1, null, "The path to a file containing the base64-encoded data to be " + "decoded. If neither the --" + ARG_NAME_DATA + " nor the --" + ARG_NAME_INPUT_FILE + " argument is provided, then the data " + "will be read from standard input.", true, true, true, false);
decodeDataFileArgument.addLongIdentifier("encodedDataFile", true);
decodeDataFileArgument.addLongIdentifier("input-file", true);
decodeDataFileArgument.addLongIdentifier("encoded-data-file", true);
decodeParser.addArgument(decodeDataFileArgument);
final FileArgument decodeOutputFileArgument = new FileArgument('o', ARG_NAME_OUTPUT_FILE, false, 1, null, "The path to a file to which the decoded data should be written. " + "If this is not provided, the decoded data will be written to " + "standard output.", false, true, true, false);
decodeOutputFileArgument.addLongIdentifier("toRawFile", true);
decodeOutputFileArgument.addLongIdentifier("output-file", true);
decodeOutputFileArgument.addLongIdentifier("to-raw-file", true);
decodeParser.addArgument(decodeOutputFileArgument);
final BooleanArgument decodeURLArgument = new BooleanArgument(null, ARG_NAME_URL, "Decode the data with the base64url mechanism rather than the " + "standard base64 mechanism.");
decodeParser.addArgument(decodeURLArgument);
final BooleanArgument decodeAddTrailingLineBreak = new BooleanArgument(null, ARG_NAME_ADD_TRAILING_LINE_BREAK, "Add a line break to the end of the decoded data.");
decodeAddTrailingLineBreak.addLongIdentifier("add-trailing-line-break", true);
decodeParser.addArgument(decodeAddTrailingLineBreak);
decodeParser.addExclusiveArgumentSet(decodeDataArgument, decodeDataFileArgument);
final LinkedHashMap<String[], String> decodeExamples = new LinkedHashMap<>(StaticUtils.computeMapCapacity(3));
decodeExamples.put(new String[] { "decode", "--data", "SGVsbG8=" }, "Base64-decodes the string 'SGVsbG8=' and writes the result to " + "standard output.");
decodeExamples.put(new String[] { "decode", "--inputFile", "encoded-data.txt", "--outputFile", "decoded-data.txt" }, "Base64-decodes the data contained in the 'encoded-data.txt' file " + "and writes the result to the 'raw-data.txt' file.");
decodeExamples.put(new String[] { "decode" }, "Base64-decodes data read from standard input and writes the result " + "to standard output.");
final SubCommand decodeSubCommand = new SubCommand(SUBCOMMAND_NAME_DECODE, "Decodes base64-encoded data.", decodeParser, decodeExamples);
parser.addSubCommand(decodeSubCommand);
}
use of com.unboundid.util.args.SubCommand in project ldapsdk by pingidentity.
the class CommandLineTool method getToolInvocationProvidedArguments.
/**
* Updates the provided argument list with object pairs that comprise the
* set of arguments actually provided to this tool on the command line.
*
* @param parser The argument parser for this tool.
* It must not be {@code null}.
* @param argumentsSetFromPropertiesFile A set that includes all arguments
* set from the properties file.
* @param argList The list to which the argument
* information should be added. It
* must not be {@code null}. The
* first element of each object pair
* that is added must be
* non-{@code null}. The second
* element in any given pair may be
* {@code null} if the first element
* represents the name of an argument
* that doesn't take any values, the
* name of the selected subcommand, or
* an unnamed trailing argument.
*/
private static void getToolInvocationProvidedArguments(@NotNull final ArgumentParser parser, @NotNull final Set<Argument> argumentsSetFromPropertiesFile, @NotNull final List<ObjectPair<String, String>> argList) {
final String noValue = null;
final SubCommand subCommand = parser.getSelectedSubCommand();
if (subCommand != null) {
argList.add(new ObjectPair<>(subCommand.getPrimaryName(), noValue));
}
for (final Argument arg : parser.getNamedArguments()) {
// Exclude arguments that weren't provided.
if (!arg.isPresent()) {
continue;
}
// Exclude arguments that were set from the properties file.
if (argumentsSetFromPropertiesFile.contains(arg)) {
continue;
}
if (arg.takesValue()) {
for (final String value : arg.getValueStringRepresentations(false)) {
if (arg.isSensitive()) {
argList.add(new ObjectPair<>(arg.getIdentifierString(), "*****REDACTED*****"));
} else {
argList.add(new ObjectPair<>(arg.getIdentifierString(), value));
}
}
} else {
argList.add(new ObjectPair<>(arg.getIdentifierString(), noValue));
}
}
if (subCommand != null) {
getToolInvocationProvidedArguments(subCommand.getArgumentParser(), argumentsSetFromPropertiesFile, argList);
}
for (final String trailingArgument : parser.getTrailingArguments()) {
argList.add(new ObjectPair<>(trailingArgument, noValue));
}
}
use of com.unboundid.util.args.SubCommand in project ldapsdk by pingidentity.
the class CommandLineToolInteractiveModeProcessor method validateRequiredExclusiveAndDependentArgumentSets.
/**
* Examines the arguments provided to the tool to ensure that all required,
* exclusive, and dependent argument set constraints have been satisfied.
*
* @throws ArgumentException If any required or exclusive argument
* constraints are not satisfied.
*/
private void validateRequiredExclusiveAndDependentArgumentSets() throws ArgumentException {
validateRequiredExclusiveAndDependentArgumentSets(parser);
final SubCommand selectedSubCommand = parser.getSelectedSubCommand();
if (selectedSubCommand != null) {
validateRequiredExclusiveAndDependentArgumentSets(selectedSubCommand.getArgumentParser());
}
}
Aggregations