Tools: pass Scanner to tasks and revert options management
- Remove TaskOption and central logic for processing options. It is not flexible and clear enough without investing a lot of effort. Fix is easy - just pass the scanner and let the task do what it needs to do.
This commit is contained in:
@@ -3,12 +3,11 @@ package permissions;
|
||||
import utils.ANewMap;
|
||||
import utils.FileUtils;
|
||||
import utils.TagReplacer;
|
||||
import utils.TaskOption;
|
||||
import utils.ToolTask;
|
||||
import utils.ToolsConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -25,10 +24,16 @@ public class PermissionsListWriter implements ToolTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Map<String, String> options) {
|
||||
public void execute(Scanner scanner) {
|
||||
// Ask if result should be written to file
|
||||
boolean includeDescription = options.get("include.description").equals("y");
|
||||
boolean writeToFile = options.get("write.to.file").equals("y");
|
||||
System.out.println("Include description? [Enter 'n' for no]");
|
||||
boolean includeDescription = !matches("n", scanner);
|
||||
|
||||
boolean writeToFile = false;
|
||||
if (includeDescription) {
|
||||
System.out.println("Write to file? [Enter 'y' for yes]");
|
||||
writeToFile = matches("y", scanner);
|
||||
}
|
||||
|
||||
if (!includeDescription) {
|
||||
outputSimpleList();
|
||||
@@ -39,13 +44,6 @@ public class PermissionsListWriter implements ToolTask {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<TaskOption> getOptions() {
|
||||
return Arrays.asList(
|
||||
new TaskOption("include.description", "Include description? [y/n]", "y", "y", "n"),
|
||||
new TaskOption("write.to.file", "Write to file? [y/n]", "n", "y", "n"));
|
||||
}
|
||||
|
||||
private static void generateAndWriteFile() {
|
||||
final String permissionsTagValue = generatePermissionsList();
|
||||
|
||||
@@ -83,4 +81,9 @@ public class PermissionsListWriter implements ToolTask {
|
||||
System.out.println("Total: " + nodes.size());
|
||||
}
|
||||
|
||||
private static boolean matches(String answer, Scanner sc) {
|
||||
String userInput = sc.nextLine();
|
||||
return answer.equalsIgnoreCase(userInput);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user