Ragex.CLI.Prompt (Ragex v0.10.1)

View Source

Interactive prompt utilities for CLI input.

Provides functions for getting user input, confirmations, and selections from the command line.

Summary

Functions

Prompts the user for a yes/no confirmation.

Prompts the user for text input.

Prompts the user to select multiple items from a list.

Prompts the user to enter a number.

Pauses execution and waits for user to press Enter.

Prompts the user to select from a list of options.

Functions

confirm(message, opts \\ [])

@spec confirm(
  String.t(),
  keyword()
) :: boolean()

Prompts the user for a yes/no confirmation.

Returns true for yes, false for no.

Options

  • :default - Default value if user presses enter (:yes, :no, or nil)

Examples

iex> Prompt.confirm("Delete file?")
Delete file? (y/n): y
true

iex> Prompt.confirm("Continue?", default: :yes)
Continue? (Y/n): 
true

input(message, opts \\ [])

@spec input(
  String.t(),
  keyword()
) :: String.t()

Prompts the user for text input.

Options

  • :default - Default value if user presses enter
  • :required - Whether input is required (default: false)
  • :validate - Validation function that returns {:ok, value} or {:error, reason}
  • :mask - Mask input (for passwords, default: false)

Examples

iex> Prompt.input("Enter your name")
Enter your name: Alice
"Alice"

iex> Prompt.input("API Key", mask: true)
API Key: ****
"secret"

multi_select(message, options, opts \\ [])

@spec multi_select(String.t(), [any()], keyword()) :: [any()]

Prompts the user to select multiple items from a list.

Returns a list of selected values.

Options

  • :min - Minimum number of selections required (default: 0)
  • :max - Maximum number of selections allowed (default: unlimited)
  • :display_fn - Function to format option display (default: to_string)

Examples

iex> Prompt.multi_select("Choose toppings", ["Cheese", "Pepperoni", "Olives"])
Choose toppings (enter numbers separated by commas, or 'all'):
  1. Cheese
  2. Pepperoni
  3. Olives
Select: 1,3
["Cheese", "Olives"]

number(message, opts \\ [])

@spec number(
  String.t(),
  keyword()
) :: integer() | float()

Prompts the user to enter a number.

Options

  • :min - Minimum allowed value
  • :max - Maximum allowed value
  • :default - Default value
  • :type - Number type (:integer or :float, default: :integer)

Examples

iex> Prompt.number("Enter count", min: 1, max: 100)
Enter count (1-100): 42
42

pause(message \\ "Press Enter to continue...")

@spec pause(String.t()) :: :ok

Pauses execution and waits for user to press Enter.

Examples

iex> Prompt.pause("Press Enter to continue...")
Press Enter to continue...
:ok

select(message, options, opts \\ [])

@spec select(String.t(), [any()], keyword()) :: any()

Prompts the user to select from a list of options.

Returns the selected value.

Options

  • :default - Index of default option (0-based)
  • :display_fn - Function to format option display (default: to_string)

Examples

iex> Prompt.select("Choose a color", ["Red", "Green", "Blue"])
Choose a color:
  1. Red
  2. Green
  3. Blue
Select (1-3): 2
"Green"