default string now splits on semicolons, and spaces are used for variants in default
This commit is contained in:
parent
b91056d68a
commit
9bf53f1d27
2 changed files with 25 additions and 15 deletions
|
@ -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
|
||||
|
|
34
src/main.rs
34
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() {
|
||||
|
|
Loading…
Reference in a new issue