Skip to content

Commit 23dd179

Browse files
committed
Fix the completion command's zsh completions
It's now possible to do `source <(selenium completion zsh)` in zsh and have that Do The Right Thing. You can also copy the output to a `_selenium` completion file and have zsh load that properly to avoid executing a command every time a shell starts. We don't currently properly handle sub-sub commands (eg. `selenium info tab-tab` won't produce any useful results), but this is a step in the right direction.
1 parent ee3ecbd commit 23dd179

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

java/src/org/openqa/selenium/grid/commands/CompletionCommand.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public String getDescription() {
5454

5555
@Override
5656
public Set<Role> getConfigurableRoles() {
57-
return ALL_ROLES;
57+
return Collections.singleton(Role.of("completion"));
5858
}
5959

6060
@Override
@@ -114,10 +114,10 @@ private void outputZshCompletions(PrintStream out) {
114114
Map<CliCommand, Set<DescribedOption>> allCommands = listKnownCommands();
115115

116116
// My kingdom for multiline strings
117-
out.println("#compdef selenium");
118-
out.println("local context state state_descr line");
117+
out.println("#compdef _selenium selenium");
119118
out.println("typeset -A opt_args");
120119
out.println("_selenium() {");
120+
out.println(" local context state state_descr line");
121121
out.println(" _arguments -C \\");
122122
out.println(" '(- :)--ext[Amend the classpath for Grid]: :->arg' \\");
123123
out.println(" '(-): :->command' \\");
@@ -130,7 +130,7 @@ private void outputZshCompletions(PrintStream out) {
130130
allCommands.keySet().stream()
131131
.sorted(Comparator.comparing(CliCommand::getName))
132132
.forEach(cmd -> {
133-
out.println(String.format(" '%s:%s'", cmd.getName(), cmd.getDescription().replace("'", "\\'")));
133+
out.println(String.format(" '%s:%s'", cmd.getName(), cmd.getDescription().replace("'", "'\\''")));
134134
});
135135

136136
out.println(" )");
@@ -161,7 +161,11 @@ private void outputZshCompletions(PrintStream out) {
161161
.filter(opt -> !opt.flags().isEmpty())
162162
.sorted(Comparator.comparing(opt -> opt.flags().iterator().next()))
163163
.forEach(opt -> {
164-
String quotedDesc = opt.description.replace("'", "\\''").replace(":", "\\:");
164+
String quotedDesc = opt.description().replace("'", "'\\''");
165+
int index = quotedDesc.indexOf("\n");
166+
if (index != -1) {
167+
quotedDesc = quotedDesc.substring(0, index);
168+
}
165169

166170
if (opt.flags().size() == 1) {
167171
out.println(String.format(" '%s[%s]%s'", opt.flags().iterator().next(), quotedDesc, getZshType(opt)));
@@ -181,8 +185,6 @@ private void outputZshCompletions(PrintStream out) {
181185
out.println(" _arguments $args && return");
182186
out.println("}\n\n");
183187
});
184-
185-
out.println("_selenium");
186188
}
187189

188190
private String getZshType(DescribedOption option) {

java/src/org/openqa/selenium/grid/commands/InfoCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String getDescription() {
5050

5151
@Override
5252
public Set<Role> getConfigurableRoles() {
53-
return Collections.emptySet();
53+
return Collections.singleton(Role.of("info"));
5454
}
5555

5656
@Override

java/src/org/openqa/selenium/grid/node/docker/DockerFlags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class DockerFlags implements HasRoles {
6060
@Parameter(
6161
names = {"--docker", "-D"},
6262
description = "Docker configs which map image name to stereotype capabilities (example " +
63-
"`-D selenium/standalone-firefox:latest '{\"browserName\": \"firefox\"}')",
63+
"`-D selenium/standalone-firefox:latest '{\"browserName\": \"firefox\"}'`)",
6464
arity = 2,
6565
variableArity = true,
6666
splitter = NonSplittingSplitter.class)

0 commit comments

Comments
 (0)