From 05d1f9452ae67a9f1cff2160d018aab47f58f798 Mon Sep 17 00:00:00 2001 From: woojiq Date: Fri, 4 Aug 2023 17:45:49 +0300 Subject: [PATCH] feat(health): support multiple health arguments --- helix-term/src/args.rs | 7 +++++-- helix-term/src/health.rs | 34 ++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..22131d0ffb58 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -8,7 +8,7 @@ pub struct Args { pub display_help: bool, pub display_version: bool, pub health: bool, - pub health_arg: Option, + pub health_arg: Vec, pub load_tutor: bool, pub fetch_grammars: bool, pub build_grammars: bool, @@ -42,7 +42,10 @@ impl Args { }, "--health" => { args.health = true; - args.health_arg = argv.next_if(|opt| !opt.starts_with('-')); + // Helix exists after printin health so we don't care about files + while let Some(item) = argv.next_if(|opt| !opt.starts_with('-')) { + args.health_arg.push(item); + } } "-g" | "--grammar" => match argv.next().as_deref() { Some("fetch") => args.fetch_grammars = true, diff --git a/helix-term/src/health.rs b/helix-term/src/health.rs index 8f92187778be..e435abf70941 100644 --- a/helix-term/src/health.rs +++ b/helix-term/src/health.rs @@ -328,17 +328,31 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<( Ok(()) } -pub fn print_health(health_arg: Option) -> std::io::Result<()> { - match health_arg.as_deref() { - Some("languages") => languages_all()?, - Some("clipboard") => clipboard()?, - None | Some("all") => { - general()?; - clipboard()?; - writeln!(std::io::stdout().lock())?; - languages_all()?; +pub fn print_health(health_args: Vec) -> std::io::Result<()> { + fn print_all() -> std::io::Result<()> { + general()?; + clipboard()?; + writeln!(std::io::stdout().lock())?; + languages_all()?; + Ok(()) + } + + if health_args.is_empty() { + print_all()?; + return Ok(()); + } + for (idx, health_arg) in health_args.into_iter().enumerate() { + if idx != 0 { + // Empty line + let mut stdout = std::io::stdout().lock(); + writeln!(stdout)?; + } + match health_arg.as_str() { + "languages" => languages_all()?, + "clipboard" => clipboard()?, + "all" => print_all()?, + lang => language(lang.into())?, } - Some(lang) => language(lang.to_string())?, } Ok(()) }