Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3352-If-multiple-invalid-options-are-specified-for-asadmin-only-first-is-reported #3550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# only if the new code is made subject to such option by the copyright
# holder.
#
# Portions Copyright [2019] Payara Foundation and/or affiliates

CommandSuccessful=Command {0} executed successfully.
CommandSuccessfulWithWarnings=Command {0} completed with warnings.
Expand Down Expand Up @@ -202,6 +203,7 @@ DeprecatedSyntax=Deprecated syntax, instead use:
parser.noValueAllowed=Option may not have value: {0}
parser.illegalNo="--no" illegal with non-boolean option: {0}
parser.invalidOption=Invalid option: {0}
parser.invalidOptions=Invalid options: {0}
parser.nonbooleanNotAllowed=Non-boolean option: {0}, not allowed in argument: {1}
parser.missingValue=Missing value for option: {0}
parser.invalidFileEx=Invalid file for option: --{0}: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] Payara Foundation and/or affiliates
// Portions Copyright [2018-2019] Payara Foundation and/or affiliates

package com.sun.enterprise.admin.cli;

import java.io.*;
import java.util.*;

import com.sun.enterprise.util.StringUtils;
import org.glassfish.api.admin.*;
import org.glassfish.api.admin.CommandModel.ParamModel;
import com.sun.enterprise.admin.util.CommandModelData.ParamModelData;
Expand All @@ -56,7 +58,10 @@
public class Parser {
/** MultiMap of options and values from command-line */
private ParameterMap optionsMap = new ParameterMap();


/** Set of invalid options' names from command-line */
private Set<String> invalidOptions = new HashSet<>();

/** Array of operands from command-line */
private List<String> operands = new ArrayList<String>();

Expand Down Expand Up @@ -176,7 +181,7 @@ private void parseCommandLine(final String[] argv, final int start)
opt = lookupShortOption(arg.charAt(i));
if (opt == null) {
if (!ignoreUnknown) {
throw new CommandValidationException(strings.get("parser.invalidOption", Character.toString(arg.charAt(i))));
invalidOptions.add(arg);
}
// unknown option, skip all the rest
operands.add(arg);
Expand All @@ -202,7 +207,7 @@ private void parseCommandLine(final String[] argv, final int start)
// is it a known option?
if (opt == null) {
if (!ignoreUnknown){
throw new CommandValidationException(strings.get("parser.invalidOption", arg));
invalidOptions.add(arg);
}
// unknown option, skip it
operands.add(arg);
Expand Down Expand Up @@ -240,7 +245,16 @@ private void parseCommandLine(final String[] argv, final int start)
}
}
}
setOption(opt, value);
if (invalidOptions.isEmpty()) {
setOption(opt, value);
}
}

if (invalidOptions.size() == 1) {
throw new CommandValidationException(strings.get("parser.invalidOption", invalidOptions.iterator().next()));
}
else if (invalidOptions.size() > 1) {
throw new CommandValidationException(strings.get("parser.invalidOptions", StringUtils.cat(" ", invalidOptions.toArray(new String[0]))));
}
}

Expand Down