I am currently writing some interactive mix tasks in a project I am writing and I noticed that
["", "y", "Y", "yes", "YES", "Yes"]
However, it struck me that allowing what I'll call an "implicit" confirmation with the Enter key is sometimes dangerous; e.g:
>>> Are you sure you want to continue with this very dangerous, irreversible operation? [Yn]"
Dangerous is highly contextual of course, but I'd love to have an option that requires the user to explicitly type their confirmation — in this case the Enter key would be a cancel input instead, and make the function return false.
I had a look at the code in lib/mix/lib/mix/shell/io.ex and it seems like a straightforward change — I'd be happy to contribute if this proposal were acceptable.
The change would look something like this:
Add an option; e.g:
Mix.Shell.IO.yes?("Are you sure?", explicit_yes?: true)
The option could alternatively be called :explicit?, :strict, :enter_cancels? or something else — whatever is considered most idiomatic.
Of course, this would also change the prompt slightly to indicate the behaviour of implicit input; e.g:
Are you sure? [yN]
Instead of:
Are you sure? [Yn]
Existing behaviour of this function would remain unchanged; this option would default to false and Enter would be accepted as prompt confirmation as before.
Additionally, looking at the source code — I wonder should the accepted input be case-insensitive, and allow values like "yEs" or is the aforementioned allowlist comprised of explicit values for a specific reason?
Thanks!
Darragh