ExPrompt (ex_prompt v0.2.0) View Source
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.
- Asking for a "required" answer.
- Choosing between several options.
- Asking for confirmation.
- Asking for a password.
Link to this section Summary
Functions
Asks the user to select form a list of choices. It returns either the index of the element in the list or -1 if it's not found.
Asks for confirmation to the user. It allows the user to answer or respond with the following options
Alias for string/2
.
Alias for string_required/1
.
Asks for a password.
Reads a line from :stdio
displaying the prompt that is passed in.
Same as string/2
but it will continue to "prompt" the user in case of an empty response.
Alias for confirm/2
.
Link to this section Types
Link to this section Functions
Specs
Asks the user to select form a list of choices. 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.
Examples
To ask for a favorite color in a predefined list
ExPrompt.choose("Favorite color?" , ~w(red green blue))
It's the same example above, but defines to the second option (green) as default value if none is selected.
ExPrompt.choose("Favorite color?" , ~w(red green blue), 2)
Specs
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 or the default value if it's present.
Examples
To ask whether the user wants to delete a file or not:
ExPrompt.confirm("Are you sure you want to delete this file?")
It's the same example above, returning false as default.
ExPrompt.confirm("Are you sure you want to delete this file?", false)
Specs
Alias for string/2
.
Specs
Alias for string_required/1
.
Specs
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.
Examples
ExPrompt.password("Password: ")
ExPrompt.password("Password: ", false)
Specs
Reads a line from :stdio
displaying the prompt that is passed in.
In case of any errors or :eof
this function will return the default value if present, or an empty string otherwise.
Examples
To ask a user for their name and await for the input:
ExPrompt.string("What is your name? ")
To ask for a hostname defaulting to localhost
:
ExPrompt.string("What is the hostname? ", "localhost")
Specs
Same as string/2
but it will continue to "prompt" the user in case of an empty response.
Specs
Alias for confirm/2
.