From 90e5eb8f790fd8100619180f442619a326649c2b Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 20 Nov 2024 16:10:29 -0500 Subject: [PATCH] added the PRIDE_DEFAULT env var to set the default flag --- man/pride.6 | 7 +++++++ src/main.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/man/pride.6 b/man/pride.6 index 8a4135f..0dad758 100644 --- a/man/pride.6 +++ b/man/pride.6 @@ -82,6 +82,13 @@ The rainbow flag designed for 2017 Philadelphia Pride. .It Ic transgender, trans The transgender pride flag designed by Monica Helms in 1999. .El +.Sh ENVIRONMENT +.Bl -tag -width Ds +.It PRIDE_DEFAULT +A string containing the name of a flag to use as the default when no +.Ar flag +argument is provided. +.El .Sh EXIT STATUS .Bl -tag -width Ds .It 1 diff --git a/src/main.rs b/src/main.rs index 1edc848..dbd043d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ //! main method module +use std::env::var; use pico_args::Arguments; @@ -50,7 +51,7 @@ fn main() { let state = State::new(&mut args); - let subcommand = args.subcommand().unwrap(); + let subcommand = if let Ok(Some(subcommand)) = args.subcommand() { Some(subcommand) } else { var("PRIDE_DEFAULT").ok() }; let variant = args.subcommand().unwrap(); // get color vec from matched flag