Skip to content

Instantly share code, notes, and snippets.

@comdotlinux
Created November 26, 2022 18:36
Show Gist options
  • Save comdotlinux/c8c37df48f1bb30fbb9b3e85b785dd18 to your computer and use it in GitHub Desktop.
Save comdotlinux/c8c37df48f1bb30fbb9b3e85b785dd18 to your computer and use it in GitHub Desktop.
A confirmation Dialog From WIthin Gradle.
import javax.swing.JOptionPane
tasks.register("askConfirmation") {
doLast {
if (confirmation("Do you want to answer me?")) {
logger.lifecycle("😃 You Answered Yes!!!!")
} else {
logger.lifecycle("😒 You Answered No 🤷")
}
}
}
fun confirmation(msg: String = "Continue?"): Boolean {
return if (System.console() != null) {
"y".equals(System.console().readLine("$msg [y/n] : "), ignoreCase = true)
} else {
JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, msg, "Confirm operation", JOptionPane.YES_NO_OPTION)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment