Example #1
0
  static void programRun() {
    System.out.println("Give a command: ");
    String command = scanner.next().toLowerCase();
    if (command.equals("")) {

    } else if (command.equals("exit")) {
      insideExitCommand = true;
      while (insideExitCommand) {
        System.out.println("Are you sure you want to quit? Y/N");
        command = scanner.next().toLowerCase();
        if (command.startsWith("y")) {
          System.out.println("Goodbye.");
          programIsOn = false;
          insideExitCommand = false;
        } else if (command.startsWith("n")) {
          insideExitCommand = false;
        } else {
          printCommandUnknown();
        }
      }
    } else if (command.equals("help")) {
      helpCommand();
    } else if (command.equals("opendb")) {
      openDB();
      // to be continued
    } else if (command.equals("start") || command.equals("analyze")) {
      insideStart = true;
      while (insideStart) {
        Operation operation = new Operation(scanner, flags, command);
        operation.main();
        insideStart = false;
      }
    } else if (command.equals("truncate")) {
      if (dbIsOpen()) {
        try {
          DatabaseConnection.truncateTables(flags.getConnection());
        } catch (SQLException ex) {
          printSQLException(ex);
        }
      }
    } else if (command.equals("addlang")) {
      addNewLanguage();
    } else if (command.equals("showlangs")) {
      showLanguages();
    } else if (command.equals("automatic")) {
      flags.setApproveFormsAutomatically(!flags.areFormsAutomaticallyApproved());
    } else {
      printCommandUnknown();
    }
  }