Skip to content
Snippets Groups Projects
Commit 6884ee1e authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Update on cli help

parent 00c7fccd
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ public class Action extends Command { ...@@ -77,7 +77,7 @@ public class Action extends Command {
private final static String NAVIGATE_LEFT_PANEL = "navigate-left-panel"; private final static String NAVIGATE_LEFT_PANEL = "navigate-left-panel";
private final static String GENERIC = "generic";
public Action() { public Action() {
...@@ -364,22 +364,6 @@ public class Action extends Command { ...@@ -364,22 +364,6 @@ public class Action extends Command {
} }
}; };
// Navigation
Command navigateLeftPanel = new Command() {
public String getCommand() { return NAVIGATE_LEFT_PANEL; }
public String getShortCommand() { return "nlf"; }
public String getDescription() { return "Select the edition panel on the left"; }
public String executeCommand(String command, Interpreter interpreter) {
if (!interpreter.isTToolStarted()) {
return Interpreter.TTOOL_NOT_STARTED;
}
interpreter.mgui.selectPanelOnTheLeft();
return null;
}
};
Command movePanelToTheLeftPanel = new Command() { Command movePanelToTheLeftPanel = new Command() {
public String getCommand() { return NAVIGATE_PANEL_TO_LEFT; } public String getCommand() { return NAVIGATE_PANEL_TO_LEFT; }
public String getShortCommand() { return "nptf"; } public String getShortCommand() { return "nptf"; }
...@@ -396,21 +380,7 @@ public class Action extends Command { ...@@ -396,21 +380,7 @@ public class Action extends Command {
} }
}; };
Command generic = new Command() { Command generic = new Generic();
public String getCommand() { return GENERIC; }
public String getShortCommand() { return "g"; }
public String getDescription() { return "Apply a generic function of TTool"; }
public String executeCommand(String command, Interpreter interpreter) {
if (!interpreter.isTToolStarted()) {
return Interpreter.TTOOL_NOT_STARTED;
}
ActionPerformer.actionPerformed(interpreter.mgui, null, command.trim(), null);
return null;
}
};
addAndSortSubcommand(start); addAndSortSubcommand(start);
...@@ -422,9 +392,7 @@ public class Action extends Command { ...@@ -422,9 +392,7 @@ public class Action extends Command {
addAndSortSubcommand(diplodocusOneTraceSimulation); addAndSortSubcommand(diplodocusOneTraceSimulation);
addAndSortSubcommand(diplodocusGenerateTML); addAndSortSubcommand(diplodocusGenerateTML);
addAndSortSubcommand(diplodocusUPPAAL); addAndSortSubcommand(diplodocusUPPAAL);
addAndSortSubcommand(movePanelToTheLeftPanel);
addAndSortSubcommand(navigateLeftPanel);
addAndSortSubcommand(generic); addAndSortSubcommand(generic);
} }
......
...@@ -63,8 +63,8 @@ public class Command implements CommandInterface { ...@@ -63,8 +63,8 @@ public class Command implements CommandInterface {
} }
public String getCommand() { public String getCommand() {
return "default"; return "default";
} }
public String getShortCommand() { public String getShortCommand() {
return getCommand(); return getCommand();
} }
...@@ -117,6 +117,7 @@ public class Command implements CommandInterface { ...@@ -117,6 +117,7 @@ public class Command implements CommandInterface {
return ""; return "";
} }
public String getHelp(int level) { public String getHelp(int level) {
String dec = getLevelString(level); String dec = getLevelString(level);
/*String h = ""; /*String h = "";
...@@ -139,6 +140,8 @@ public class Command implements CommandInterface { ...@@ -139,6 +140,8 @@ public class Command implements CommandInterface {
return b.toString(); return b.toString();
} }
public String getLevelString(int level) { public String getLevelString(int level) {
String ret = ""; String ret = "";
while(level > 0) { while(level > 0) {
...@@ -174,9 +177,6 @@ public class Command implements CommandInterface { ...@@ -174,9 +177,6 @@ public class Command implements CommandInterface {
} }
public void addAndSortSubcommand(Command c) { public void addAndSortSubcommand(Command c) {
/*if (subcommands.size() == 0) {
subcommands.add(c);
}*/
int index = 0; int index = 0;
for (Command cmd: subcommands) { for (Command cmd: subcommands) {
...@@ -188,4 +188,24 @@ public class Command implements CommandInterface { ...@@ -188,4 +188,24 @@ public class Command implements CommandInterface {
subcommands.add(index, c); subcommands.add(index, c);
} }
public Command getSubCommandByName(String cmd) {
String comm = cmd;
int index = cmd.indexOf(" ");
if (index > 0) {
comm = cmd.substring(0, index);
}
for (Command c: subcommands) {
if ((c.getShortCommand().compareTo(cmd) == 0) || (c.getCommand().compareTo(cmd) == 0)) {
if (index == -1) {
return c;
}
return c.getSubCommandByName(cmd.substring(index+1, cmd.length()).trim());
}
}
return null;
}
} }
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import common.ConfigurationTTool;
import common.SpecConfigTTool;
import launcher.RTLLauncher;
import myutil.FileUtils;
import myutil.PluginManager;
import myutil.TraceManager;
import tmltranslator.*;
import tmltranslator.dsez3engine.InputInstance;
import tmltranslator.dsez3engine.OptimizationModel;
import tmltranslator.dsez3engine.OptimizationResult;
import ui.ActionPerformer;
import ui.MainGUI;
import ui.TGComponent;
import ui.TURTLEPanel;
import ui.util.IconManager;
import java.io.File;
import java.util.BitSet;
import java.util.*;
/**
* Class Generic
* Creation: 12/04/2019
* Version 2.0 12/04/2019
*
* @author Ludovic APVRILLE
*/
public class Generic extends Command {
private final static String GENERIC = "generic";
public Generic() {
}
public String getCommand() { return GENERIC; }
public String getShortCommand() { return "g"; }
public String getDescription() { return "Apply a generic function of TTool"; }
public String executeCommand(String command, Interpreter interpreter) {
if (!interpreter.isTToolStarted()) {
return Interpreter.TTOOL_NOT_STARTED;
}
ActionPerformer.actionPerformed(interpreter.mgui, null, command.trim(), null);
return null;
}
public void fillSubCommands() {
}
}
...@@ -101,7 +101,7 @@ public class Help extends Command { ...@@ -101,7 +101,7 @@ public class Help extends Command {
} }
Command c = interpreter.getCommandByName(command); Command c = interpreter.getSubCommandByName(command);
if (c == null) { if (c == null) {
return Interpreter.BAD_COMMAND_NAME; return Interpreter.BAD_COMMAND_NAME;
...@@ -109,6 +109,7 @@ public class Help extends Command { ...@@ -109,6 +109,7 @@ public class Help extends Command {
interpreter.print(c.getHelp(1)); interpreter.print(c.getHelp(1));
return null; return null;
} }
...@@ -116,4 +117,6 @@ public class Help extends Command { ...@@ -116,4 +117,6 @@ public class Help extends Command {
public void fillSubCommands() { public void fillSubCommands() {
} }
} }
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
* *
* ludovic.apvrille AT enst.fr * ludovic.apvrille AT enst.fr
* *
* This software is a computer program whose purpose is to allow the * This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to * edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram, * allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces * and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes. * from INRIA Rhone-Alpes.
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL * modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL * license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info". * "http://www.cecill.info".
* *
* As a counterpart to the access to the source code and rights to copy, * As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only * modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the * with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited * economic rights, and the successive licensors have only limited
* liability. * liability.
* *
* In this respect, the user's attention is drawn to the risks associated * In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the * with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software, * software by the user in light of its specific status of free software,
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* requirements in conditions enabling the security of their systems and/or * requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the * data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security. * same conditions as regards security.
* *
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms. * knowledge of the CeCILL license and that you accept its terms.
*/ */
...@@ -39,18 +39,15 @@ ...@@ -39,18 +39,15 @@
package cli; package cli;
import common.ConfigurationTTool;
import common.SpecConfigTTool;
import launcher.RTLLauncher;
import myutil.Conversion; import myutil.Conversion;
import myutil.PluginManager; import myutil.Terminal;
import myutil.TerminalProviderInterface;
import myutil.TraceManager; import myutil.TraceManager;
import ui.*; import ui.MainGUI;
import ui.util.IconManager;
import java.io.*;
import myutil.*;
import java.util.*; import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;
/** /**
* Class Interpreter * Class Interpreter
...@@ -59,7 +56,7 @@ import java.util.*; ...@@ -59,7 +56,7 @@ import java.util.*;
* *
* @author Ludovic APVRILLE * @author Ludovic APVRILLE
*/ */
public class Interpreter implements Runnable, TerminalProviderInterface { public class Interpreter implements Runnable, TerminalProviderInterface {
public final static Command[] commands = {new Action(), new Help(), new History(), new Print(), new Quit(), public final static Command[] commands = {new Action(), new Help(), new History(), new Print(), new Quit(),
new TestSpecific(), new TML(), new Set(), new Wait()}; new TestSpecific(), new TML(), new Set(), new Wait()};
...@@ -68,12 +65,12 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -68,12 +65,12 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
public final static String UNKNOWN = "Unknown command"; public final static String UNKNOWN = "Unknown command";
public final static String BAD = "Badly formatted expression"; public final static String BAD = "Badly formatted expression";
public final static String BAD_WAIT_VALUE = "Must provide a int value > 0"; public final static String BAD_WAIT_VALUE = "Must provide a int value > 0";
public final static String BAD_VAR_VALUE ="Unvalid value for variable"; public final static String BAD_VAR_VALUE = "Unvalid value for variable";
public final static String BAD_VAR_NAME ="Unvalid variable name"; public final static String BAD_VAR_NAME = "Unvalid variable name";
public final static String UNKNOWN_NEXT_COMMAND ="Invalid action: "; public final static String UNKNOWN_NEXT_COMMAND = "Invalid action: ";
public final static String TTOOL_NOT_STARTED ="TTool is not yet started. Cannot execute command."; public final static String TTOOL_NOT_STARTED = "TTool is not yet started. Cannot execute command.";
public final static String TTOOL_ALREADY_STARTED ="TTool is already started. Cannot execute command."; public final static String TTOOL_ALREADY_STARTED = "TTool is already started. Cannot execute command.";
public final static String BAD_COMMAND_NAME ="The provided command is invalid"; public final static String BAD_COMMAND_NAME = "The provided command is invalid";
private String script; private String script;
...@@ -129,7 +126,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -129,7 +126,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
executeLine(line, cptLine, false); executeLine(line, cptLine, false);
cptLine ++; cptLine++;
printPrompt(cptLine); printPrompt(cptLine);
} }
} }
...@@ -144,7 +141,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -144,7 +141,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
currentLine = 0; currentLine = 0;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
String line = scanner.nextLine(); String line = scanner.nextLine();
currentLine ++; currentLine++;
executeLine(line, currentLine, true); executeLine(line, currentLine, true);
} }
...@@ -183,9 +180,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -183,9 +180,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
} }
//TraceManager.addDev("Handling line: " + lineWithNoVariable); //TraceManager.addDev("Handling line: " + lineWithNoVariable);
String [] commandInfo = lineWithNoVariable.split(" "); String[] commandInfo = lineWithNoVariable.split(" ");
if ((commandInfo == null) || (commandInfo.length < 1)){ if ((commandInfo == null) || (commandInfo.length < 1)) {
System.out.println("Empty command"); System.out.println("Empty command");
if (exitOnError) { if (exitOnError) {
System.exit(-1); System.exit(-1);
...@@ -193,18 +190,17 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -193,18 +190,17 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
} }
// Analyze current line // Analyze current line
error = ""; error = "";
for(Command c: commands) { for (Command c : commands) {
if (commandInfo[0].compareTo(c.getCommand()) == 0) { if (commandInfo[0].compareTo(c.getCommand()) == 0) {
error = c.executeCommand( lineWithNoVariable.substring(c.getCommand().length(), error = c.executeCommand(lineWithNoVariable.substring(c.getCommand().length(),
lineWithNoVariable.length()).trim(), this); lineWithNoVariable.length()).trim(), this);
TraceManager.addDev("Command executed"); TraceManager.addDev("Command executed");
break; break;
} }
if (commandInfo[0].compareTo(c.getShortCommand()) == 0) { if (commandInfo[0].compareTo(c.getShortCommand()) == 0) {
error = c.executeCommand( lineWithNoVariable.substring(c.getShortCommand().length(), error = c.executeCommand(lineWithNoVariable.substring(c.getShortCommand().length(),
lineWithNoVariable.length()).trim(), this); lineWithNoVariable.length()).trim(), this);
TraceManager.addDev("Short Command executed"); TraceManager.addDev("Short Command executed");
break; break;
...@@ -233,9 +229,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -233,9 +229,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
String initialLine = input; String initialLine = input;
int index; int index;
while((index = input.indexOf("$")) > -1) { while ((index = input.indexOf("$")) > -1) {
ret = ret + input.substring(0, index); ret = ret + input.substring(0, index);
input = input.substring(index+1, input.length()); input = input.substring(index + 1, input.length());
int indexSpace = input.indexOf(" "); int indexSpace = input.indexOf(" ");
String varName; String varName;
if (indexSpace == -1) { if (indexSpace == -1) {
...@@ -243,7 +239,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -243,7 +239,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
input = ""; input = "";
} else { } else {
varName = input.substring(0, indexSpace); varName = input.substring(0, indexSpace);
input = input.substring(indexSpace+1, input.length()); input = input.substring(indexSpace + 1, input.length());
} }
// Identifying variable // Identifying variable
...@@ -282,10 +278,21 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -282,10 +278,21 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
return show; return show;
} }
public Command getCommandByName(String cmd) { public Command getSubCommandByName(String cmd) {
for (Command c: commands) { String comm = cmd;
if ((c.getShortCommand().compareTo(cmd) == 0) || (c.getCommand().compareTo(cmd) == 0)) {
return c; int index = cmd.indexOf(" ");
if (index > 0) {
comm = cmd.substring(0, index);
}
for (Command c : commands) {
if ((c.getShortCommand().compareTo(comm) == 0) || (c.getCommand().compareTo(comm) == 0)) {
if (index == -1) {
return c;
}
return c.getSubCommandByName(cmd.substring(index+1, cmd.length()).trim());
} }
} }
return null; return null;
...@@ -293,7 +300,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -293,7 +300,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
public String getHelp() { public String getHelp() {
StringBuffer buf = new StringBuffer(""); StringBuffer buf = new StringBuffer("");
for(Command c:commands) { for (Command c : commands) {
buf.append(c.getHelp(0) + "\n"); buf.append(c.getHelp(0) + "\n");
} }
return buf.toString(); return buf.toString();
...@@ -306,7 +313,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -306,7 +313,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
// History // History
public String printAllFormerCommands() { public String printAllFormerCommands() {
StringBuffer sb = new StringBuffer(""); StringBuffer sb = new StringBuffer("");
for(int i=0; i<formerCommands.size(); i++) { for (int i = 0; i < formerCommands.size(); i++) {
sb.append("" + i + "\t" + formerCommands.get(i) + "\n"); sb.append("" + i + "\t" + formerCommands.get(i) + "\n");
} }
print(sb.toString()); print(sb.toString());
...@@ -338,13 +345,13 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -338,13 +345,13 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
// From the split, determine commands already entered and completes it // From the split, determine commands already entered and completes it
Vector<Command> listOfCommands = findCommands(split, 0); Vector<Command> listOfCommands = findCommands(split, 0);
if (listOfCommands.size()== 0) { if (listOfCommands.size() == 0) {
return false; return false;
} }
for(Command c: listOfCommands) { for (Command c : listOfCommands) {
System.out.println(""+c.getCommand()); System.out.println("" + c.getCommand());
return true; return true;
} }
return true; return true;
...@@ -364,9 +371,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface { ...@@ -364,9 +371,9 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
Vector<Command> couldBe = new Vector<>(); Vector<Command> couldBe = new Vector<>();
// Search of all compatible commands starting with s // Search of all compatible commands starting with s
for (Command c: commands) { for (Command c : commands) {
if (c.getShortCommand().startsWith(s) || c.getCommand().startsWith(s)) { if (c.getShortCommand().startsWith(s) || c.getCommand().startsWith(s)) {
Vector<Command> others = c.findCommands(split, index+1); Vector<Command> others = c.findCommands(split, index + 1);
if (others != null) { if (others != null) {
couldBe.addAll(others); couldBe.addAll(others);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment