arti/
subcommands.rs

1//! Arti CLI subcommands.
2
3#[cfg(feature = "onion-service-service")]
4pub(crate) mod hss;
5
6#[cfg(feature = "hsc")]
7pub(crate) mod hsc;
8
9#[cfg(feature = "onion-service-cli-extra")]
10pub(crate) mod keys;
11
12#[cfg(feature = "onion-service-cli-extra")]
13pub(crate) mod raw;
14
15pub(crate) mod proxy;
16
17use crate::Result;
18
19use anyhow::anyhow;
20
21use std::io::{self, Write};
22
23/// Prompt the user to confirm by typing yes or no.
24///
25/// Loops until the user confirms or declines,
26/// returning true if they confirmed.
27///
28/// Returns an error if an IO error occurs.
29fn prompt(msg: &str) -> Result<bool> {
30    /// The accept message.
31    const YES: &str = "yes";
32    /// The decline message.
33    const NO: &str = "no";
34
35    let mut proceed = String::new();
36
37    print!("{} (type {YES} or {NO}): ", msg);
38    io::stdout().flush().map_err(|e| anyhow!(e))?;
39    loop {
40        io::stdin()
41            .read_line(&mut proceed)
42            .map_err(|e| anyhow!(e))?;
43
44        if proceed.trim_end() == YES {
45            return Ok(true);
46        }
47
48        match proceed.trim_end().to_lowercase().as_str() {
49            NO | "n" => return Ok(false),
50            _ => {
51                proceed.clear();
52                continue;
53            }
54        }
55    }
56}