use of execute.CommandInterpreter in project Lab5 by Arslanka.
the class Application method startInteractiveMode.
public void startInteractiveMode() {
try {
String fileName = this.fileName[0];
final File file = new File(fileName.trim());
final TextFile textFile = new TextFile(file);
final JsonFile jsonFile = new JsonFile(textFile);
collection.add(jsonFile.read());
CommandInterpreter commandInterpreter = new CommandInterpreter(this.commandsByName, supplierMap, this.printer, requestMap);
boolean running = true;
while (running) {
printer.println(("Enter the command:"), REQUEST);
try {
running = commandInterpreter.run(new ArrayList<>(Arrays.asList(sc.nextLine().trim().split("\\s+"))));
} catch (NoSuchElementException e) {
running = false;
} catch (RecursiveCallException | InvalidCommandNameException | IllegalArgumentException | JsonParseException e) {
printer.println(e.getMessage(), ERROR);
}
}
printer.println("Program execution stopped", CONSOLE);
} catch (NoSuchElementException e) {
printer.println("The program ended incorrectly. Please restart the program.", ERROR);
} catch (ArrayIndexOutOfBoundsException e) {
printer.println("You didn't specify the file name to populate the collection", ERROR);
} catch (Exception e) {
printer.println(e.getMessage(), ERROR);
}
}
Aggregations