โŒจ๏ธ
โŒจ๏ธ Build CLI Tools with Larz ยท LARZ-801 ยท Session 4 of 5

Interactive Prompts & Progress

Great CLIs talk with the user: asking questions when needed, and showing progress on long tasks. larzprompt and larzprogress make both easy - and testable.

โฑ 7 min read๐Ÿ“… Updated 2026-07-27๐Ÿ“Š Tables, charts & examples

Two touches make a command-line tool feel alive and considerate: asking the user for input when it's needed (a confirmation, a choice, a password), and showing progress on anything that takes more than a moment. larzprompt and larzprogress handle both cleanly - and larzprompt is built to be unit-testable, which interactive code usually isn't.

Ask the user well

Prompt for confirmations, selections, text and passwords - with re-prompting on invalid input - instead of crashing or making the user pass everything as flags.

from larzprompt import confirm, select, text

if confirm('Delete 3 files?'):
    choice = select('Backup first?', ['yes', 'no', 'cancel'])
    name = text('New name:')
    ...
PromptFor
confirmYes/no confirmations before risky actions
selectPick from a list of choices
text / integerFree input, validated
passwordHidden secret input

Good prompts guide the user and prevent mistakes (like confirming before something destructive), and re-ask on bad input rather than failing.

Show progress, and stay testable

For anything slow, a progress bar or spinner reassures the user it's working. And because larzprompt takes injectable input/output, your interactive flows are actually unit-testable.

from larzprogress import progress
for item in progress(items, label='Processing'):
    handle(item)   # a live progress bar, pipe-safe
๐ŸŽฏ
Feedback that's honest and testable. A long task with no feedback feels frozen; larzprogress shows a bar or spinner that (like larztui) auto-silences when output isn't a terminal, so it never garbles logs. And larzprompt's injectable input/output means you can unit-test 'if the user confirms, it deletes' with a fake input - something interactive code is normally painful to test. Considerate feedback and testability, both handled.

Make it interactive

  • Prompt when needed - confirm/select/text/password, with re-prompting.
  • Confirm risky actions - a yes/no before anything destructive.
  • Show progress - bars/spinners for slow work; pipe-safe.
  • Stay testable - injectable I/O lets you unit-test interactive flows.

๐ŸŽฏ Key takeaways

  • Great CLIs ask the user when needed and show progress on long tasks.
  • larzprompt gives confirm/select/text/password with re-prompting; confirm risky actions.
  • larzprogress shows pipe-safe bars/spinners so slow tasks don't feel frozen.
  • larzprompt's injectable I/O makes interactive flows unit-testable - rare and valuable.

Frequently asked

When should a CLI prompt versus take everything as flags?

Balance convenience with automatability. Flags/arguments are essential because they let the tool be scripted and automated (a tool that always stops to ask can't be used in a pipeline or cron job). But interactive prompts are valuable for confirmations before destructive actions, for guiding occasional/human use, and when required input is missing. A good pattern: accept everything as flags for automation, but prompt for missing required values or dangerous confirmations when run interactively - and provide a way to skip prompts (like a --yes flag) for scripts. So: default to flags for scriptability, add prompts thoughtfully for safety and human friendliness, and always leave an escape hatch for automation.

How do you even unit-test interactive prompts?

Normally it's painful, because the code calls out to real stdin/stdout, so a test would hang waiting for input. larzprompt solves this by letting you inject the input and output - in a test you provide a fake input source that returns canned answers and capture the output, so you can assert 'when the user answers yes, the function proceeds; when no, it aborts' with no real interaction. This means your interactive logic (which is often exactly the risky, decision-making part of a tool) can be tested like any other code, rather than being an untested black box. Designing for injectable I/O is what makes that possible, and it's built into larzprompt.

Session 4 of 5 complete

Next up: Package & Ship Your CLI

Continue to Session 5 โ†’

Related lessons

More in this course

Course home → · Browse all courses →