-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
38 lines (29 loc) · 925 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mod passphrase;
mod words;
use std::io::IsTerminal;
use clap::Parser;
use eyre::Result;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// The number of words in the passphrase
#[arg(short, long, default_value = "4")]
num_words: usize,
/// The string to separate words in the passphrase
#[arg(short, long, default_value = " ")]
separator: String,
/// A path to a dictionary file. A builtin dictionary is used if not provided.
#[arg(short, long)]
dict_path: Option<String>,
}
fn main() -> Result<()> {
let args = Args::parse();
let mut words: Vec<String> = words::list(args.dict_path)?;
let mut rng = rand::thread_rng();
let passphrase = passphrase::new(&mut rng, &mut words, args.num_words, &args.separator)?;
print!("{passphrase}");
if std::io::stdout().is_terminal() {
println!();
}
Ok(())
}