Skip to content
Snippets Groups Projects
Commit fe1d1d52 authored by dgelessus's avatar dgelessus
Browse files

Include colons in command names for more flexibility

parent e8249298
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ import io.github.spencerpark.jupyter.messages.DisplayData; ...@@ -28,7 +28,7 @@ import io.github.spencerpark.jupyter.messages.DisplayData;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public final class ProBKernel extends BaseKernel { public final class ProBKernel extends BaseKernel {
private static final Pattern COMMAND_PATTERN = Pattern.compile("\\s*\\:(.*)"); private static final Pattern COMMAND_PATTERN = Pattern.compile("\\s*(\\:.*)");
private final @NotNull Map<@NotNull String, @NotNull ReplCommand> commands; private final @NotNull Map<@NotNull String, @NotNull ReplCommand> commands;
private @NotNull Trace trace; private @NotNull Trace trace;
...@@ -39,8 +39,8 @@ public final class ProBKernel extends BaseKernel { ...@@ -39,8 +39,8 @@ public final class ProBKernel extends BaseKernel {
this.commands = new HashMap<>(); this.commands = new HashMap<>();
final ReplCommand help = new HelpCommand(); final ReplCommand help = new HelpCommand();
this.commands.put("?", help); this.commands.put(":?", help);
this.commands.put("help", help); this.commands.put(":help", help);
this.trace = new Trace(classicalBFactory.create("MACHINE repl END").load()); this.trace = new Trace(classicalBFactory.create("MACHINE repl END").load());
} }
......
...@@ -19,7 +19,7 @@ public final class CommandExecutionException extends RuntimeException { ...@@ -19,7 +19,7 @@ public final class CommandExecutionException extends RuntimeException {
} }
private static @NotNull String formatMessage(final @NotNull String commandName, final @NotNull String message) { private static @NotNull String formatMessage(final @NotNull String commandName, final @NotNull String message) {
return String.format(":%s: %s", commandName, message); return String.format("%s: %s", commandName, message);
} }
public @NotNull String getCommandName() { public @NotNull String getCommandName() {
......
...@@ -30,7 +30,6 @@ public final class HelpCommand implements ReplCommand { ...@@ -30,7 +30,6 @@ public final class HelpCommand implements ReplCommand {
for (final String commandName : names) { for (final String commandName : names) {
final ReplCommand command = kernel.getCommands().get(commandName); final ReplCommand command = kernel.getCommands().get(commandName);
assert command != null; assert command != null;
sb.append(':');
sb.append(commandName); sb.append(commandName);
sb.append(' '); sb.append(' ');
sb.append(command.getShortHelp()); sb.append(command.getShortHelp());
...@@ -38,7 +37,10 @@ public final class HelpCommand implements ReplCommand { ...@@ -38,7 +37,10 @@ public final class HelpCommand implements ReplCommand {
} }
return new DisplayData(sb.toString()); return new DisplayData(sb.toString());
} else if (args.size() == 1) { } else if (args.size() == 1) {
final String commandName = args.get(0); String commandName = args.get(0);
if (!commandName.startsWith(":")) {
commandName = ':' + commandName;
}
final ReplCommand command = kernel.getCommands().get(commandName); final ReplCommand command = kernel.getCommands().get(commandName);
if (command == null) { if (command == null) {
throw new CommandExecutionException(name, String.format("Cannot display help for unknown command \"%s\"", commandName)); throw new CommandExecutionException(name, String.format("Cannot display help for unknown command \"%s\"", commandName));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment