diff --git a/man/pride.6 b/man/pride.6 index bf9f913..2ddde90 100644 --- a/man/pride.6 +++ b/man/pride.6 @@ -87,7 +87,11 @@ The transgender pride flag designed by Monica Helms in 1999. .It PRIDE_DEFAULT A string containing the name of one or more flags to use as the default when no .Ar flag -argument is provided. If the string contains a space-separated list of flags, a random one will be selected from the list. +argument is provided. If the string contains a semicolon-separated list of flags, a random one will be selected from the list. If a space is found in the chosen substring, it will be used to provide the +.Ar flag +and +.Ar variant +arguments. .El .Sh EXIT STATUS .Bl -tag -width Ds diff --git a/src/main.rs b/src/main.rs index e4d5011..f93820c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,10 @@ use crate::{ static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub const FLAG_HELP: [&str;2] = [ "-h", "--help" ]; -pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ]; -pub const FLAG_SIZE: [&str;2] = [ "-s", "--size"]; -pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ]; +pub const FLAG_HELP: [&str;2] = [ "-h", "--help" ]; +pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ]; +pub const FLAG_SIZE: [&str;2] = [ "-s", "--size" ]; +pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ]; fn main() { // collect args @@ -54,19 +54,25 @@ fn main() { let state = State::new(&mut args); - let subcommand = - if let Ok(Some(subcommand)) = args.subcommand() { Some(subcommand) } + let ( subcommand, variant ) = + if let Ok(Some(subcommand)) = args.subcommand() { ( Some(subcommand), args.subcommand().unwrap()) } else if let Ok(default) = var("PRIDE_DEFAULT") { - if default.is_empty() { None } - else if default.contains(' ') { - let split: Vec<&str> = default.split(' ').collect(); + if default.is_empty() { ( None, None ) } + else if default.contains(';') { + let split: Vec<&str> = default.split(';').collect(); if let Ok(time) = UNIX_EPOCH.elapsed() { let index = oorandom::Rand32::new(time.as_secs()).rand_u32(); - Some(split[index as usize % split.len()].to_owned()) - } else { None } - } else { Some(default) } - } else { None }; - let variant = args.subcommand().unwrap(); + let chosen = split[index as usize % split.len()].to_owned(); + if chosen.contains(' ') { + let split: Vec<&str> = chosen.split(' ').collect(); + ( Some(split[0].to_owned()), Some(split[1].to_owned()) ) + } else { ( Some(chosen), None ) } + } else { ( None, None ) } + } else if default.contains(' ') { + let split: Vec<&str> = default.split(' ').collect(); + ( Some(split[0].to_owned()), Some(split[1].to_owned()) ) + } else { ( Some(default), None ) } + } else { ( None, None ) }; // get color vec from matched flag let flag: Flag = match subcommand.as_deref() {