ExPrompt is a helper package to add interactivity to your command line applications as easy as possible.
It allows common operations such as: asking for an answer (required or not), choosing between several options, asking for confirmation and asking for a password.
The package can be installed by adding ex_prompt
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_prompt, "~> 0.1.5"}
]
end
See the full documentation and API at hexdocs/ex_prompt.
Prompts the user for some input.
iex> ExPrompt.string("What is your name?")
iex> What is your name? |
Same as string
but if we get no response, it will keep asking until we do.
iex> ExPrompt.string_required("What is your name?")
iex> What is your name? |
Asks the user to choose between several options from a list. It returns either the index of the element in the list or -1 if it's not found.
This method tries first to get said element by the list number, if it fails it will attempt to get the index from the list of choices by the value that the user wrote.
iex> ExPrompt.choose("What is your favorite color?", ~w(Red Green Blue))
iex>
1) Red
2) Green
3) Blue
What is your favorite color? |
Asks for confirmation to the user. It allows the user to answer or respond with the following options:
- Yes, yes, YES, Y, y
- No, no, NO, N, n
In case that the answer is none of the above, it will prompt again until we do.
iex> ExPrompt.confirm("Are you sure?")
iex> Are you sure? [Yn] |
Alias for confirm(prompt)
.
Asks for a password.
This method will hide the password by default as the user types.
If that's not the desired behavior, it accepts false
, and the password
will be shown as it's being typed.
iex> ExPrompt.password("Your password:")
iex> Your password: |
Check LICENSE.