"The main method must call the askOperation() method to get the current operation."
but i am calling it!
package com.codegym.task.task31.task3110;
import com.codegym.task.task31.task3110.command.Command;
import com.codegym.task.task31.task3110.command.ExitCommand;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Archiver {
public static Operation askOperation() throws IOException {
ConsoleHelper.writeMessage("Please type the number of the desired operation:");
ConsoleHelper.writeMessage("0 - Zip files into an archive");
ConsoleHelper.writeMessage("1 - Add a file to an archive");
ConsoleHelper.writeMessage("2 - Remove a file from an archive");
ConsoleHelper.writeMessage("3 - Extract an archive");
ConsoleHelper.writeMessage("4 - View the contents of an archive");
ConsoleHelper.writeMessage("5 - Exit");
int ordinal = ConsoleHelper.readInt();
Operation operation = null;
for(Operation op : Operation.values()) {
if(op.ordinal() == ordinal)
operation = op;
}
return operation;
}
public static void main(String[] args) throws Exception {
System.out.println("Please enter the full path to the archive (don't forget that the file name is also part of the full path!).");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
String fileToZip = reader.readLine();
Path path = Paths.get(fileName);
Path pathToZip = Paths.get(fileToZip);
ZipFileManager zipFileManager = new ZipFileManager(path);
System.out.println("Please enter the path to the file to be zipped (don't confuse this with the archive file, which we already entered!).");
zipFileManager.createZip(pathToZip);
Operation operation;
while (true) {
try {
operation = askOperation();
CommandExecutor.execute(operation);
if(operation == Operation.EXIT)
break;
} catch (NoSuchFieldException e) {
ConsoleHelper.writeMessage("You didn't select an archive or you selected an invalid file.");
} catch (Exception e) {
ConsoleHelper.writeMessage("An error occurred. Please check the entered data.");
}
}
ExitCommand exitCommand = new ExitCommand();
exitCommand.execute();
}
}