make symbols optional
This commit is contained in:
parent
4b19fbfed6
commit
4a01bd5faa
2 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,8 @@ pub struct Args {
|
|||
#[arg(short, default_value_t = 16)]
|
||||
pub length: usize,
|
||||
#[arg(short)]
|
||||
pub symbols: bool,
|
||||
#[arg(short)]
|
||||
pub write_to_file: bool,
|
||||
#[arg(short, default_value_t = String::from("generated_pwd.txt"))]
|
||||
pub file: String,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use clap::Parser;
|
||||
use rand::Rng;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::iter;
|
||||
|
||||
use crate::Args;
|
||||
|
@ -15,8 +15,16 @@ impl RandomString {
|
|||
let mut rng = rand::thread_rng();
|
||||
let char = || CHARSET[rng.gen_range(0..CHARSET.len())] as char;
|
||||
|
||||
let s: String = iter::repeat_with(char).take(args.length).collect();
|
||||
|
||||
s
|
||||
if args.symbols {
|
||||
let s: String = iter::repeat_with(char).take(args.length).collect();
|
||||
s
|
||||
} else {
|
||||
let s: String = rng
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(args.length)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue