1
//! Arti CLI subcommands.
2

            
3
#[cfg(feature = "onion-service-service")]
4
pub(crate) mod hss;
5

            
6
#[cfg(feature = "hsc")]
7
pub(crate) mod hsc;
8

            
9
#[cfg(feature = "onion-service-cli-extra")]
10
pub(crate) mod keys;
11

            
12
#[cfg(feature = "onion-service-cli-extra")]
13
pub(crate) mod raw;
14

            
15
pub(crate) mod proxy;
16

            
17
use crate::Result;
18

            
19
use anyhow::anyhow;
20

            
21
use 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.
29
6
fn 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
6
    let mut proceed = String::new();
36

            
37
6
    print!("{} (type {YES} or {NO}): ", msg);
38
6
    io::stdout().flush().map_err(|e| anyhow!(e))?;
39
    loop {
40
6
        io::stdin()
41
6
            .read_line(&mut proceed)
42
6
            .map_err(|e| anyhow!(e))?;
43

            
44
6
        if proceed.trim_end() == YES {
45
            return Ok(true);
46
6
        }
47

            
48
6
        match proceed.trim_end().to_lowercase().as_str() {
49
6
            NO | "n" => return Ok(false),
50
            _ => {
51
                proceed.clear();
52
                continue;
53
            }
54
        }
55
    }
56
6
}