CLI Option Prompt¶
It's also possible to, instead of just showing an error, ask for the missing value with prompt=True:
š¤ Other versions and variants
And then your program will ask the user for it in the terminal:
Customize the prompt¶
You can also set a custom prompt, passing the string that you want to use instead of just True:
š¤ Other versions and variants
And then your program will ask for it using with your custom prompt:
Confirmation prompt¶
In some cases you could want to prompt for something and then ask the user to confirm it by typing it twice.
You can do it passing the parameter confirmation_prompt=True.
Let's say it's a CLI app to delete a project:
š¤ Other versions and variants
And it will prompt the user for a value and then for the confirmation:
$ uv run python main.py
// Your app will first prompt for the project name, and then for the confirmation
# Project name: $ Old Project
# Repeat for confirmation: $ Old Project
Deleting project Old Project
// If the user doesn't type the same, receives an error and a new prompt
$ uv run python main.py
# Project name: $ Old Project
# Repeat for confirmation: $ New Spice
Error: The two entered values do not match
# Project name: $ Old Project
# Repeat for confirmation: $ Old Project
Deleting project Old Project
// Now it works š