Archived
0

hotfix: NullPointerException

This commit is contained in:
2015-12-16 14:45:32 +03:00
parent 9a80bf7ade
commit d9d2bbaca5
2 changed files with 10 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ import java.util.List;
* 2015 * 2015
*/ */
public class CommandCompleter implements Completer { public class CommandCompleter implements Completer {
protected StringsCompleter stringsCompleter = new StringsCompleter(); protected StringsCompleter stringsCompleter;
@Override @Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) { public int complete(String buffer, int cursor, List<CharSequence> candidates) {

View File

@@ -2,11 +2,14 @@ package ru.dmitriymx.shell;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import jline.console.completer.ArgumentCompleter; import jline.console.completer.ArgumentCompleter;
import jline.console.completer.StringsCompleter;
import ru.dmitriymx.shell.commands.Command; import ru.dmitriymx.shell.commands.Command;
import ru.dmitriymx.shell.commands.ExitCommand; import ru.dmitriymx.shell.commands.ExitCommand;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author DmitriyMX <mail@dmitriymx.ru> * @author DmitriyMX <mail@dmitriymx.ru>
@@ -23,6 +26,8 @@ public class Shell {
private CommandCompleter commandCompleter; private CommandCompleter commandCompleter;
private Formatter formatter; private Formatter formatter;
protected boolean run = false; protected boolean run = false;
private Map<String, Command> commandMap = new HashMap<>();
private StringsCompleter stringsCompleter = new StringsCompleter();
public void start() throws IOException, InterruptedException { public void start() throws IOException, InterruptedException {
if (sysErr == null) overrideSysOutErr(); if (sysErr == null) overrideSysOutErr();
@@ -31,8 +36,10 @@ public class Shell {
if (promt == null) promt = ":"; if (promt == null) promt = ":";
console.setPrompt(ConsoleReader.RESET_LINE + promt); console.setPrompt(ConsoleReader.RESET_LINE + promt);
console.addCompleter((commandCompleter = new CommandCompleter())); console.addCompleter((commandCompleter = new CommandCompleter()));
commandCompleter.stringsCompleter = stringsCompleter;
newErr.setConsoleReader(console); newErr.setConsoleReader(console);
commandLoop = new CommandLoop(this); commandLoop = new CommandLoop(this);
commandLoop.commandMap = commandMap;
if (!commandLoop.commandMap.containsKey("exit")) { if (!commandLoop.commandMap.containsKey("exit")) {
addCommand(new ExitCommand()); addCommand(new ExitCommand());
@@ -62,8 +69,8 @@ public class Shell {
public void addCommand(Command command) { public void addCommand(Command command) {
command.setShell(this); command.setShell(this);
String name = command.getName().toLowerCase(); String name = command.getName().toLowerCase();
commandLoop.commandMap.put(name, command); commandMap.put(name, command);
commandCompleter.stringsCompleter.getStrings().add(name); stringsCompleter.getStrings().add(name);
} }
public boolean isRunning() { public boolean isRunning() {