diff --git a/src/RemoteSimulationControl.java b/src/RemoteSimulationControl.java index a7a7c08247cc433ddf8a75b94a41de4c8c3531ba..2148d5543a9bfffb0e9980859af50d74e69a1903 100755 --- a/src/RemoteSimulationControl.java +++ b/src/RemoteSimulationControl.java @@ -81,14 +81,10 @@ public class RemoteSimulationControl extends Thread { System.out.println("port: port on which the simulator accepts commands (default: 3490). Must be a positive integer value"); } - public static void printHelp(String cmd) { - System.out.println("\nCommands supported by the simulator:"); + public static void printHelp(CommandParser cp, String cmd) { + System.out.println("\nCommand " + cmd + ": "); System.out.println("-------------------------------------------------------------"); - System.out.println("cmd <raw comand>: used to send a raw command to the simulator"); - System.out.println("help: print that help"); - System.out.println("help <command>: print the help on the given command <command>"); - System.out.println("list: list all possible simulation commands"); - System.out.println("quit: quit the remote interface to simulation"); + System.out.println(cp.getHelp(cmd)); System.out.println("-------------------------------------------------------------\n"); } @@ -194,7 +190,7 @@ public class RemoteSimulationControl extends Thread { // Thread reading from keyboard public void run() { - + String tmp; String input; BufferedReader dataIn; @@ -219,7 +215,11 @@ public class RemoteSimulationControl extends Thread { System.out.println("bye-bye"); System.exit(-1); } else if (cp.isHelpCommand(input)) { - printHelp(input); + tmp = cp.getHelpWithCommand(input); + if ((tmp != null) && (tmp.length() > 0)) { + } else { + printHelp(cp, input); + } } else if (cp.isListCommand(input)) { System.out.println("Available commands:"); System.out.println(cp.getCommandList()); diff --git a/src/remotesimulation/CommandParser.java b/src/remotesimulation/CommandParser.java index 0b1c9cbb22979724609123c2d76ffbcc7a683e5b..1512dc86f22f56407c49f7fbd1c9f0cf07372dfc 100755 --- a/src/remotesimulation/CommandParser.java +++ b/src/remotesimulation/CommandParser.java @@ -90,7 +90,25 @@ public class CommandParser { return null; } - return tmp; + return tmp; + + + } + + public String getHelp(String cmd) { + StringBuffer sb = new StringBuffer(""); + boolean commandFound = false; + + for(SimulationCommand sc: commandList) { + if (sc.userCommand.equals(cmd)) { + sb.append(sc.getSynopsis() + "\n" + sc.help + "\n"); + } + } + if (commandFound) { + return sb.toString(); + } else { + return "Command not found"; + } } public boolean isQuitCommand(String cmd) { @@ -124,9 +142,13 @@ public class CommandParser { private void fillCommandList() { SimulationCommand sc; + int[] params; + String[] paramNames; // kill-simulator - sc = new SimulationCommand("kill-simulator", "0", 0, 0, 0, 0, "Terminates the remote simulator"); + params = new int[0]; + paramNames = new String[0]; + sc = new SimulationCommand("kill-simulator", "0", params, paramNames, "Terminates the remote simulator"); commandList.add(sc); }