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
|
.It PRIDE_DEFAULT
|
||||||
A string containing the name of one or more flags to use as the default when no
|
A string containing the name of one or more flags to use as the default when no
|
||||||
.Ar flag
|
.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
|
.El
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
.Bl -tag -width Ds
|
.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");
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
pub const FLAG_HELP: [&str;2] = [ "-h", "--help" ];
|
pub const FLAG_HELP: [&str;2] = [ "-h", "--help" ];
|
||||||
pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ];
|
pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ];
|
||||||
pub const FLAG_SIZE: [&str;2] = [ "-s", "--size"];
|
pub const FLAG_SIZE: [&str;2] = [ "-s", "--size" ];
|
||||||
pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ];
|
pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ];
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// collect args
|
// collect args
|
||||||
|
@ -54,19 +54,25 @@ fn main() {
|
||||||
|
|
||||||
let state = State::new(&mut args);
|
let state = State::new(&mut args);
|
||||||
|
|
||||||
let subcommand =
|
let ( subcommand, variant ) =
|
||||||
if let Ok(Some(subcommand)) = args.subcommand() { Some(subcommand) }
|
if let Ok(Some(subcommand)) = args.subcommand() { ( Some(subcommand), args.subcommand().unwrap()) }
|
||||||
else if let Ok(default) = var("PRIDE_DEFAULT") {
|
else if let Ok(default) = var("PRIDE_DEFAULT") {
|
||||||
if default.is_empty() { None }
|
if default.is_empty() { ( None, None ) }
|
||||||
else if default.contains(' ') {
|
else if default.contains(';') {
|
||||||
let split: Vec<&str> = default.split(' ').collect();
|
let split: Vec<&str> = default.split(';').collect();
|
||||||
if let Ok(time) = UNIX_EPOCH.elapsed() {
|
if let Ok(time) = UNIX_EPOCH.elapsed() {
|
||||||
let index = oorandom::Rand32::new(time.as_secs()).rand_u32();
|
let index = oorandom::Rand32::new(time.as_secs()).rand_u32();
|
||||||
Some(split[index as usize % split.len()].to_owned())
|
let chosen = split[index as usize % split.len()].to_owned();
|
||||||
} else { None }
|
if chosen.contains(' ') {
|
||||||
} else { Some(default) }
|
let split: Vec<&str> = chosen.split(' ').collect();
|
||||||
} else { None };
|
( Some(split[0].to_owned()), Some(split[1].to_owned()) )
|
||||||
let variant = args.subcommand().unwrap();
|
} 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
|
// get color vec from matched flag
|
||||||
let flag: Flag = match subcommand.as_deref() {
|
let flag: Flag = match subcommand.as_deref() {
|
||||||
|
|
Loading…
Reference in a new issue