| 84 | } |
| 85 | |
| 86 | private static class Help implements CliCommand { |
| 87 | |
| 88 | private final Set<CliCommand> commands; |
| 89 | |
| 90 | public Help(Set<CliCommand> commands) { |
| 91 | this.commands = commands; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public String getName() { |
| 96 | return "Selenium Server commands"; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Set<Role> getConfigurableRoles() { |
| 101 | return Collections.emptySet(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Set<Object> getFlagObjects() { |
| 106 | return Collections.emptySet(); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public String getDescription() { |
| 111 | return "A list of all the commands available. To use one, run `java -jar selenium.jar " |
| 112 | + "commandName`."; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public Executable configure(PrintStream out, PrintStream err, String... args) { |
| 117 | return () -> { |
| 118 | int longest = |
| 119 | commands.stream() |
| 120 | .filter(CliCommand::isShown) |
| 121 | .map(CliCommand::getName) |
| 122 | .max(Comparator.comparingInt(String::length)) |
| 123 | .map(String::length) |
| 124 | .orElse(0) |
| 125 | + 2; // two space padding either side |
| 126 | |
| 127 | PrintWriter outWriter = new WrappedPrintWriter(out, 72, 0); |
| 128 | outWriter.append(getName()).append("\n\n"); |
| 129 | outWriter.append(getDescription()).append("\n").append("\n"); |
| 130 | |
| 131 | int indent = Math.min(longest + 2, 25); |
| 132 | String format = " %-" + longest + "s"; |
| 133 | |
| 134 | PrintWriter indented = new WrappedPrintWriter(out, 72, indent); |
| 135 | commands.stream() |
| 136 | .filter(CliCommand::isShown) |
| 137 | .forEach( |
| 138 | cmd -> |
| 139 | indented |
| 140 | .format(format, cmd.getName()) |
| 141 | .append(cmd.getDescription()) |
| 142 | .append("\n")); |
| 143 |
nothing calls this directly
no outgoing calls
no test coverage detected