Prompting a user for a secret is not too uncommon, especially when building CLI applications. Due to an
issue that has remained unresolved for many years,
:io.get_password() does not work when invoked in a Mix task or through
escript. This is unfortunate as I would guess that these are the primary environments that users are likely to use that function. I believe that Elixir would benefit from a standard method that can accomplish this functionality both in normal operation and in the environments mentioned above.
Hex currently has an
implementation that appears to be stable, and I believe it would suitable to adopt it as a utility method in Kernel.IO. Ideally, the behavior would wrap the Erlang library similar to how other functions in the module do, however, I feel the logic to compensate for the problem in :io would either require matching the error tuple:
{:error, {:request, {:get_password, :unicode}}}
or checking environment conditions to see if the Erlang method is likely to succeed, neither of which seem like a great solution.
If there is any reason that the Hex implemenation is not suitable as a standard in the absence of support from :io, I'm really interested, especially if there are portability issues.
In the mean time, I'll adopt the function into my own project with a reference to Hex :P