Don't prompt to confirm non-mutating nomulus EPP tool commands

This is accomplished by making all non-mutating commands function with dry run set
to true, which also has the pleasurable side effect of not prompting for dry-run
mutating commands either, which also do nothing different/special on the second
run.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192149150
This commit is contained in:
mcilwain 2018-04-09 10:40:20 -07:00 committed by Ben McIlwain
parent 013558c814
commit 3bbaf585e5
15 changed files with 248 additions and 48 deletions

View file

@ -32,7 +32,11 @@ public abstract class ConfirmingCommand implements Command {
if (checkExecutionState()) {
init();
printLineIfNotEmpty(prompt());
if (force || promptForYes("Perform this command?")) {
if (dontRunCommand()) {
// This typically happens when all of the work is accomplished inside of prompt(), so do
// nothing further.
return;
} else if (force || promptForYes("Perform this command?")) {
System.out.println(execute());
printLineIfNotEmpty(postExecute());
} else {
@ -49,6 +53,11 @@ public abstract class ConfirmingCommand implements Command {
/** Initializes the command. */
protected void init() throws Exception {}
/** Whether to NOT run the command. Override to true for dry-run commands. */
protected boolean dontRunCommand() {
return false;
}
/** Returns the optional extra confirmation prompt for the command. */
protected String prompt() throws Exception {
return "";