#prompt #challenge #user #pause #command-line #dangerous

bin+lib challenge-prompt

challenge-prompt 在执行危险操作前让用户暂停

4 个版本 (破坏性)

0.4.0 2022 年 4 月 30 日
0.3.0 2022 年 1 月 4 日
0.2.0 2018 年 10 月 27 日
0.1.0 2018 年 9 月 25 日

#1897 in 命令行工具

Apache-2.0

13KB
196

challenge-prompt

challenge-prompt 在执行危险操作前让用户暂停。

Crates.io

命令行工具

安装

$ cargo install challenge-prompt  # with cargo
$ nix profile install 'git+https://gitlab.com/abstract-binary/challenge-prompt'  # with nix

运行

$ challenge-prompt
Solve: (5 + 15) mod 5 = ?

用法

Usage: challenge-prompt [-a] [-p] [--phrase <phrase>] [-y] [-v] [--retries <retries>]

Make the user pause before doing something dangerous.

Options:
  -a, --arithmetic  prompt the user to solve a simple arithmetic problem
                    (default challenge)
  -p, --mistake     prompt the user to type in "I am probably making a mistake."
  --phrase          prompt the user to type in exactly the given phrase
  -y, --yes         prompt the user to type in 'y' or 'yes'
  -v, --version     print version information
  --retries         how many retries to allow before failing (default: 1)
  --help            display usage information

Notes:
  Set environment variable CHALLENGE_PROMPT_SEED to an u32 to fix the RNG seed.

Error codes:
  0 User passed the challenge.
  1 User failed the challenge or an error was encountered.

库示例

将此添加到您的 Cargo.toml

[dependencies]
challenge-prompt = "0.3"

并将其添加到您的 crate 根目录

extern crate challenge_prompt;

基本示例

extern crate challenge_prompt;
    
let mut rng = challenge_prompt::Rng::new_from_time().unwrap();
if !challenge_prompt::Challenge::Arithmetic.prompt(&mut rng) {
   panic!("user failed the challenge")
}

另请参阅完整的 文档

依赖关系

~0.4–1MB
~23K SLoC