Allow tool execution with argument

This commit is contained in:
Gabriele C 2016-05-05 20:20:40 +02:00
parent 09e2845cea
commit 084cdd0d3a
2 changed files with 23 additions and 6 deletions

View File

@ -29,16 +29,28 @@ public final class ToolsRunner {
File toolsFolder = new File(ToolsConstants.TOOLS_SOURCE_ROOT);
Map<String, ToolTask> tasks = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
collectTasksInDirectory(toolsFolder, tasks);
listAllTasks(tasks);
// Prompt user for task and handle input
System.out.println("Please enter the task to run:");
String inputTask;
Scanner scanner = new Scanner(System.in);
String inputTask = scanner.nextLine();
ToolTask task = tasks.get(inputTask);
boolean interactive = true;
if(args == null || args.length == 0) {
listAllTasks(tasks);
// Prompt user for task and handle input
System.out.println("Please enter the task to run:");
inputTask = scanner.nextLine();
} else {
interactive = false;
inputTask = args[0];
}
ToolTask task = tasks.get(inputTask);
if (task != null) {
task.execute(scanner);
if(interactive) {
task.execute(scanner);
} else {
task.execute(null);
}
} else {
System.out.println("Unknown task");
}

View File

@ -25,6 +25,11 @@ public class PermissionsListWriter implements ToolTask {
@Override
public void execute(Scanner scanner) {
if(scanner == null) {
generateAndWriteFile();
return;
}
// Ask if result should be written to file
System.out.println("Include description? [Enter 'n' for no]");
boolean includeDescription = !matches("n", scanner);