mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Remove the "shell" command from the completions, and allow empty lines
Even though you couldn't run a "shell" inside a "shell", the completion still assumed you could :( On the way - fixing error on empty lines: when you just press "enter", the shell should ignore it rather than try to run it as a command (and getting an error, obviously) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=191605029
This commit is contained in:
parent
3218a9b77e
commit
3338b91c84
2 changed files with 13 additions and 12 deletions
|
@ -89,16 +89,6 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
||||||
jcommander.addConverterFactory(new ParameterFactory());
|
jcommander.addConverterFactory(new ParameterFactory());
|
||||||
jcommander.setProgramName(programName);
|
jcommander.setProgramName(programName);
|
||||||
|
|
||||||
// Create the "help" and "shell" commands (these are special in that they don't have a default
|
|
||||||
// constructor).
|
|
||||||
jcommander.addCommand("help", new HelpCommand(jcommander));
|
|
||||||
ShellCommand shellCommand = null;
|
|
||||||
if (isFirstUse) {
|
|
||||||
shellCommand = new ShellCommand(this);
|
|
||||||
jcommander.addCommand("shell", shellCommand);
|
|
||||||
isFirstUse = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create all command instances. It would be preferrable to do this in the constructor, but
|
// Create all command instances. It would be preferrable to do this in the constructor, but
|
||||||
// JCommander mutates the command instances and doesn't reset them so we have to do it for every
|
// JCommander mutates the command instances and doesn't reset them so we have to do it for every
|
||||||
// run.
|
// run.
|
||||||
|
@ -111,8 +101,17 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shellCommand != null) {
|
// Create the "help" and "shell" commands (these are special in that they don't have a default
|
||||||
|
// constructor).
|
||||||
|
jcommander.addCommand("help", new HelpCommand(jcommander));
|
||||||
|
ShellCommand shellCommand = null;
|
||||||
|
if (isFirstUse) {
|
||||||
|
isFirstUse = false;
|
||||||
|
shellCommand = new ShellCommand(this);
|
||||||
|
// We have to build the completions based on the jcommander *before* we add the "shell"
|
||||||
|
// command - to avoid completion for the "shell" command itself.
|
||||||
shellCommand.buildCompletions(jcommander);
|
shellCommand.buildCompletions(jcommander);
|
||||||
|
jcommander.addCommand("shell", shellCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -102,6 +102,9 @@ public class ShellCommand implements Command {
|
||||||
String line;
|
String line;
|
||||||
while ((line = getLine()) != null) {
|
while ((line = getLine()) != null) {
|
||||||
String[] lineArgs = parseCommand(line);
|
String[] lineArgs = parseCommand(line);
|
||||||
|
if (lineArgs.length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
runner.run(lineArgs);
|
runner.run(lineArgs);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -242,5 +245,4 @@ public class ShellCommand implements Command {
|
||||||
.collect(toImmutableList());
|
.collect(toImmutableList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue