Skip to content

Commit

Permalink
solved the inconsistency of comparator arguments - now only takes spa…
Browse files Browse the repository at this point in the history
…ce before the value (no argument with =)
  • Loading branch information
patrikcerbak committed Oct 19, 2023
1 parent e4ec709 commit d52b500
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ final public class HelpMessage {
" " + ArgumentsDeclaration.forceArg.getHelp() + "\n" +
" " + ArgumentsDeclaration.formattingArg.getName() + ArgumentsDeclaration.formattingArg.getUsage() + "\n" +
" " + ArgumentsDeclaration.formattingArg.getHelp() + "\n" +
" " + ArgumentsDeclaration.exactTestsArg.getName() + ArgumentsDeclaration.exactTestsArg.getUsage() + "\n" +
" " + ArgumentsDeclaration.exactTestsArg.getHelp() + "\n" +
" " + ArgumentsDeclaration.useDefaultBuildArg.getName() + ArgumentsDeclaration.useDefaultBuildArg.getUsage() + "\n" +
" " + ArgumentsDeclaration.useDefaultBuildArg.getHelp() + "\n" +
"\n" +
"Query string syntax:\n" +
JobsByQuery.queryStringUsage +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public final class ArgumentsDeclaration {
public static final Argument pathArg = new Argument("--path", "A system path to a directory with your jenkins jobs. This argument is mandatory", " <path/to/jenkins/jobs>");
public static final Argument nvrArg = new Argument("--nvr", "To specify what builds to take (only builds with specified NVRs). The syntax is described below.", " <nvrquery>");
public static final Argument historyArg = new Argument("--history", "To specify the maximum number of builds to look in.", " <number>");
public static final Argument skipFailedArg = new Argument("--skip-failed", "Specify whether the comparator should skip failed tests (only take successful and unstable) or take all. The default value is true.", "=<true/false>");
public static final Argument skipFailedArg = new Argument("--skip-failed", "Specify whether the comparator should skip failed tests (only take successful and unstable) or take all. The default value is true.", " <true/false>");
public static final Argument forceArg = new Argument("--force", "Used for forcing vague requests, that could potentially take a long time.", "");
public static final Argument onlyVolatileArg = new Argument("--only-volatile", "Specify true to show only non stable tests with the arguments list and compare (shows only tests, that are NOT failed everywhere). The default value is false.", "=<true/false>");
public static final Argument onlyVolatileArg = new Argument("--only-volatile", "Specify true to show only non stable tests with the arguments list and compare (shows only tests, that are NOT failed everywhere). The default value is false.", " <true/false>");
public static final Argument exactTestsArg = new Argument("--exact-tests", "Specify (with regex) the exact tests to show only. The rest of tests will be ignored.", " <regex>");
public static final Argument formattingArg = new Argument("--formatting", "Specify the output formatting (plain, color or html). The default is plain.", "=<plain/color/html>");
public static final Argument useDefaultBuildArg = new Argument("--use-default-build", "If set to true and no matching build with given NVR was found, the tool will use the latest (default) build instead. Default value is false.", "=<true/false>");
public static final Argument formattingArg = new Argument("--formatting", "Specify the output formatting (plain, color or html). The default is plain.", " <plain/color/html>");
public static final Argument useDefaultBuildArg = new Argument("--use-default-build", "If set to true and no matching build with given NVR was found, the tool will use the latest (default) build instead. Default value is false.", " <true/false>");
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public static Options parse(String[] arguments) {
JobsByRegex jobsByRegex = new JobsByRegex();

for (int i = 0; i < arguments.length; i++) {
String[] splitArg = arguments[i].split("=");
// delete all leading - characters
String currentArg = splitArg[0].replaceAll("^-+", "--");
String currentArg = arguments[i].replaceAll("^-+", "--");

if (!currentArg.matches("^--.*")) {
throw new RuntimeException("Unknown argument " + arguments[i] + ", did you forget the leading hyphens (--)?");
Expand Down Expand Up @@ -67,67 +66,46 @@ public static Options parse(String[] arguments) {

} else if (currentArg.equals(ArgumentsDeclaration.pathArg.getName())) {
// --path
if (i + 1 <= arguments.length) {
options.setJobsPath(arguments[++i]);
} else {
throw new RuntimeException("Expected path to jobs after --path.");
}
options.setJobsPath(getArgumentValue(arguments, i++));

} else if (currentArg.equals(ArgumentsDeclaration.nvrArg.getName())) {
// --nvr
if (i + 1 <= arguments.length) {
options.setNvrQuery(arguments[++i]);
} else {
throw new RuntimeException("Expected NVR after --nvr.");
}
options.setNvrQuery(getArgumentValue(arguments, i++));

} else if (currentArg.equals(ArgumentsDeclaration.historyArg.getName())) {
// --history
if (i + 1 <= arguments.length) {
options.setNumberOfBuilds(Integer.parseInt(arguments[++i]));
} else {
throw new RuntimeException("Expected number of builds after --history.");
}
options.setNumberOfBuilds(Integer.parseInt(getArgumentValue(arguments, i++)));

} else if (currentArg.equals(ArgumentsDeclaration.skipFailedArg.getName())) {
// --skip-failed
if (splitArg.length == 2 && splitArg[1].equals("false")) {
options.setSkipFailed(false);
}
options.setSkipFailed(Boolean.parseBoolean(getArgumentValue(arguments, i++)));

} else if (currentArg.equals(ArgumentsDeclaration.forceArg.getName())) {
// --force
options.setForceVague(true);

} else if (currentArg.equals(ArgumentsDeclaration.onlyVolatileArg.getName())) {
// --only-volatile
if (splitArg.length == 2 && splitArg[1].equals("true")) {
options.setOnlyVolatile(true);
}
options.setOnlyVolatile(Boolean.parseBoolean(getArgumentValue(arguments, i++)));

} else if (currentArg.equals(ArgumentsDeclaration.exactTestsArg.getName())) {
// --exact-tests
if (i + 1 <= arguments.length) {
options.setExactTestsRegex(arguments[++i]);
} else {
throw new RuntimeException("Expected the exact tests regex after --exact-tests.");
}
options.setExactTestsRegex(getArgumentValue(arguments, i++));

} else if (currentArg.equals(ArgumentsDeclaration.formattingArg.getName())) {
// --formatting
if (splitArg.length == 2 && splitArg[1].equals("color")) {
String formatting = getArgumentValue(arguments, i++);
if (formatting.equals("color") || formatting.equals("colour")) {
options.setFormatter(new ColorFormatter(System.out));
} else if (splitArg.length == 2 && splitArg[1].equals("html")) {
} else if (formatting.equals("html")) {
options.setFormatter(new HtmlFormatter(System.out));
} else if (splitArg.length == 2 && !splitArg[1].equals("plain")) {
} else if (!formatting.equals("plain")) {
throw new RuntimeException("Unexpected formatting specified.");
}

} else if (currentArg.equals(ArgumentsDeclaration.useDefaultBuildArg.getName())) {
// --use-default-build
if (splitArg.length == 2 && splitArg[1].equals("true")) {
options.setUseDefaultBuild(true);
}
options.setUseDefaultBuild(Boolean.parseBoolean(getArgumentValue(arguments, i++)));

// parsing arguments of the jobs providers
} else if (jobsByQuery.getSupportedArgs().contains(currentArg) || jobsByRegex.getSupportedArgs().contains(currentArg)) {
Expand All @@ -141,11 +119,8 @@ public static Options parse(String[] arguments) {
}
// check if the argument is compatible with current jobs provider
if (options.getJobsProvider().getSupportedArgs().contains(currentArg)) {
if (i + 1 <= arguments.length) {
options.getJobsProvider().parseArguments(currentArg, arguments[++i]);
} else {
throw new RuntimeException("Expected a value after " + currentArg + ".");
}
options.getJobsProvider().parseArguments(currentArg, getArgumentValue(arguments, i++));

} else {
throw new RuntimeException("Cannot combine arguments from multiple job providers.");
}
Expand Down Expand Up @@ -175,4 +150,12 @@ public static Options parse(String[] arguments) {

return options;
}

private static String getArgumentValue(String[] arguments, int i) {
if (i + 1 < arguments.length) {
return arguments[i + 1];
} else {
throw new RuntimeException("Expected some value after " + arguments[i] + " argument.");
}
}
}

0 comments on commit d52b500

Please sign in to comment.