added pattern tokens help argument

This commit is contained in:
ika4422 2026-04-08 13:29:43 +01:00
parent 7af9a92785
commit f9a479f4b5
No known key found for this signature in database
GPG key ID: F7FBF981D2A33785
2 changed files with 22 additions and 2 deletions

View file

@ -41,7 +41,7 @@ struct Args {
decode: Option<String>,
#[arg(short, long)]
/// Generates codes from a user-defined pattern (n = number; l = letter; L = uppercase letter; a = alphanumeric; A = uppercase alphanumeric)
/// Generates codes from a user-defined pattern (see --tokens for token list)
generate: Option<String>,
#[arg(short, long, default_value_t = 1)]
@ -53,9 +53,13 @@ struct Args {
no_doll: bool,
#[arg(short, long, default_value_t = false)]
/// Specifies the encoding/decoding method as text, not as an integer
/// Specifies the encoding/decoding method as text, instead of an integer
text: bool,
#[arg(long, default_value_t = false)]
/// List all available pattern tokens
tokens: bool,
#[arg(long)]
/// Display the license for dolltool
license: bool,
@ -69,6 +73,11 @@ fn main() {
process::exit(1);
}
if args.tokens {
println!("{}", pattern_gen::TOKEN_HELP);
process::exit(0);
}
if let Some(pattern) = args.generate {
for _ in 0..args.count {
let generated = generate_from_pattern(&pattern);

View file

@ -8,6 +8,17 @@ const ALNUM_LOWER: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";
const ALNUM_UPPER: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ALNUM_MIXED: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
pub const TOKEN_HELP: &str = "\
Pattern Tokens:
n digit (0-9)
l letter lower (a-z)
L letter upper (A-Z)
m letter mixed (a-z, A-Z)
a alnum lower (0-9, a-z)
A alnum upper (0-9, A-Z)
x alnum mixed (0-9, a-z, A-Z)
* any other character is used literally";
fn pick(rng: &mut impl rand::Rng, pool: &[u8]) -> char {
pool[rng.random_range(0..pool.len())] as char
}