zuul extra wip
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package de.szut.zuul;
|
||||
|
||||
import org.java_websocket.WebSocket;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
@@ -21,7 +22,6 @@ import java.util.Scanner;
|
||||
public class Parser
|
||||
{
|
||||
private CommandWords commands; // holds all valid command words
|
||||
private Scanner reader; // source of command input
|
||||
|
||||
/**
|
||||
* Create a parser to read from the terminal window.
|
||||
@@ -29,39 +29,30 @@ public class Parser
|
||||
public Parser()
|
||||
{
|
||||
commands = new CommandWords();
|
||||
reader = new Scanner(System.in);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The next command from the user.
|
||||
*/
|
||||
public Command getCommand()
|
||||
public Command getCommand(String inputLine, WebSocket conn)
|
||||
{
|
||||
String inputLine; // will hold the full input line
|
||||
String word1 = null;
|
||||
String word2 = null;
|
||||
|
||||
System.out.print("> "); // print prompt
|
||||
|
||||
inputLine = reader.nextLine();
|
||||
|
||||
// Find up to two words on the line.
|
||||
Scanner tokenizer = new Scanner(inputLine);
|
||||
if(tokenizer.hasNext()) {
|
||||
word1 = tokenizer.next(); // get first word
|
||||
if(tokenizer.hasNext()) {
|
||||
word2 = tokenizer.next(); // get second word
|
||||
// note: we just ignore the rest of the input line.
|
||||
}
|
||||
if (inputLine == null || inputLine.trim().isEmpty()) {
|
||||
// Falls die Eingabe leer oder null ist, eine ungültige Eingabe zurückgeben
|
||||
return new Command(null, null);
|
||||
}
|
||||
|
||||
// Now check whether this word is known. If so, create a command
|
||||
// with it. If not, create a "null" command (for unknown command).
|
||||
if(commands.isCommand(word1)) {
|
||||
// Entferne führende und nachfolgende Leerzeichen und teile die Eingabe in Wörter
|
||||
String[] words = inputLine.trim().split("\\s+");
|
||||
|
||||
String word1 = words[0]; // Das erste Wort
|
||||
String word2 = words.length > 1 ? words[1] : null; // Das zweite Wort, falls vorhanden
|
||||
|
||||
// Jetzt prüfen, ob das erste Wort ein gültiger Befehl ist.
|
||||
if (commands.isCommand(word1)) {
|
||||
return new Command(word1, word2);
|
||||
}
|
||||
else {
|
||||
return new Command(null, word2);
|
||||
} else {
|
||||
// Wenn der Befehl ungültig ist, ein null-Command zurückgeben
|
||||
return new Command(null, word2);
|
||||
}
|
||||
}
|
||||
public String showCommands()
|
||||
|
||||
Reference in New Issue
Block a user