[Proposal] Add explicit confirmation option to `Mix.Shell.IO.yes?`

57 views
Skip to first unread message

Darragh Enright

unread,
Apr 10, 2021, 8:23:11 AM4/10/21
to elixir-lang-core
Hi there!

I am currently writing some interactive mix tasks in a project I am writing and I noticed that Mix.Shell.IO.yes? accepts any trimmed input that matches the following allowlist of values:

["", "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

José Valim

unread,
Apr 10, 2021, 8:26:08 AM4/10/21
to elixir-l...@googlegroups.com
We could support default: :yes | :no. A PR is welcome!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/caa27f55-f1ac-4df1-a1fd-1e8902b7d33cn%40googlegroups.com.

Darragh Enright

unread,
Apr 10, 2021, 8:26:11 AM4/10/21
to elixir-lang-core
Oh, this is my first proposal so if I have forgotten anything just let me know :)

Darragh Enright

unread,
Apr 10, 2021, 8:29:13 AM4/10/21
to elixir-lang-core
Hi José :)

Yes, even better! I like that. I'll get a PR together.
Reply all
Reply to author
Forward
0 new messages