Crate challenge_prompt

source ·
Expand description

challenge_prompt makes the user pause before doing something.

A “challenge” prompt introduces a hurdle the user has to pass before continuing. This is useful in deployment scripts or in scary commands to make sure they were not typed by rote or pulled out of a shell history by mistake.

Available prompts are:

  • arithmetic: Asks the user to solve a problem like (12 + 7) mod 4,
  • phrase: Asks the user to type in a phrase like “I am probably making a mistake” exactly,
  • yes: Asks the user to type in ‘y’ or ‘yes’.

This crate is both a library and a small command line application for use in shell scripts.

Command-line example

$ cargo install challenge-prompt
$ challenge-prompt
Solve: (5 + 9) mod 6 = ?

Library example

[dependencies]
challenge_prompt = "0.2"
extern crate challenge_prompt;

if !challenge_prompt::Challenge::Arithmetic.prompt() {
   panic!("user failed the challenge")
}

Enums

Constants

Functions

Generic prompt implementation: print out the prompt, read a line of input, and return whether it matches expected or not.