From 45c61369c82c42b86f0235fffb2cc6025bd318df Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 7 Jan 2026 13:08:23 -0700 Subject: [PATCH] feat: Improved CLI readability by creating a separate Global Options section for global flags --- src/main.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9324092..4baa095 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,15 @@ extern crate assertables; use anyhow::Result; -use clap::{CommandFactory, Parser, crate_authors, crate_description, crate_name, crate_version}; +use clap::{ + Args, CommandFactory, Parser, crate_authors, crate_description, crate_name, crate_version, +}; use clap_complete::generate; use crossterm::execute; use crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; +use indoc::indoc; use log::{debug, error, warn}; use network::NetworkTrait; use ratatui::Terminal; @@ -64,6 +67,13 @@ mod utils; struct Cli { #[command(subcommand)] command: Option, + #[command(flatten)] + global: GlobalOpts, +} + +#[derive(Args, Debug)] +#[command(next_help_heading = "Global Options")] +struct GlobalOpts { #[arg( long, global = true, @@ -98,9 +108,12 @@ struct Cli { #[arg( long, global = true, - help = "For multi-instance configurations, you need to specify the name of the instance configuration that you want to use. - This is useful when you have multiple instances of the same Servarr defined in your config file. - By default, if left empty, the first configured Servarr instance listed in the config file will be used." + help = indoc!{" + For multi-instance configurations, you need to specify the name of the instance configuration that you want to use. + + This is useful when you have multiple instances of the same Servarr defined in your config file. + By default, if left empty, the first configured Servarr instance listed in the config file will be used. + "} )] servarr_name: Option, } @@ -114,13 +127,13 @@ async fn main() -> Result<()> { let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); let args = Cli::parse(); - let mut config = if let Some(ref config_file) = args.config_file { + let mut config = if let Some(ref config_file) = args.global.config_file { load_config(config_file.to_str().expect("Invalid config file specified"))? } else { confy::load("managarr", "config")? }; let theme_name = config.theme.clone(); - let spinner_disabled = args.disable_spinner; + let spinner_disabled = args.global.disable_spinner; debug!("Managarr loaded using config: {config:?}"); config.validate(); config.post_process_initialization(); @@ -165,8 +178,8 @@ async fn main() -> Result<()> { }); start_ui( &app, - &args.themes_file, - args.theme.unwrap_or(theme_name.unwrap_or_default()), + &args.global.themes_file, + args.global.theme.unwrap_or(theme_name.unwrap_or_default()), ) .await?; }