Skip to content

Commit

Permalink
[java] Simplification of TNG Grid main method, merging duplicated cla…
Browse files Browse the repository at this point in the history
…uses
  • Loading branch information
barancev committed Feb 12, 2019
1 parent 9aca1dc commit 80ec7e4
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions java/server/src/org/openqa/selenium/grid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static java.util.Comparator.comparing;

import org.openqa.selenium.cli.CliCommand;
import org.openqa.selenium.cli.CliCommand.Executable;
import org.openqa.selenium.cli.WrappedPrintWriter;

import java.io.PrintWriter;
Expand All @@ -35,34 +34,21 @@ public static void main(String[] args) throws Exception {
Set<CliCommand> commands = new TreeSet<>(comparing(CliCommand::getName));
ServiceLoader.load(CliCommand.class).forEach(commands::add);

String commandName;
String[] remainingArgs;

switch (args.length) {
case 0:
commandName = "help";
remainingArgs = new String[0];
break;

case 1:
commandName = args[0];
remainingArgs = new String[0];
break;

default:
commandName = args[0];
remainingArgs = new String[args.length - 1];
System.arraycopy(args, 1, remainingArgs, 0, args.length - 1);
break;
}
if (args.length == 0) {
new Help(commands).configure().run();

} else {
String commandName = args[0];
String[] remainingArgs = new String[args.length - 1];
System.arraycopy(args, 1, remainingArgs, 0, args.length - 1);

CliCommand command = commands.parallelStream()
.filter(cmd -> commandName.equals(cmd.getName()))
.findFirst()
.orElse(new Help(commands));
CliCommand command = commands.parallelStream()
.filter(cmd -> commandName.equals(cmd.getName()))
.findFirst()
.orElse(new Help(commands));

Executable primed = command.configure(remainingArgs);
primed.run();
command.configure(remainingArgs).run();
}
}

private static class Help implements CliCommand {
Expand Down

0 comments on commit 80ec7e4

Please sign in to comment.