Skip to content

Commit

Permalink
feat(health): support multiple health arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
woojiq committed Aug 4, 2023
1 parent bc73740 commit 05d1f94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
7 changes: 5 additions & 2 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Args {
pub display_help: bool,
pub display_version: bool,
pub health: bool,
pub health_arg: Option<String>,
pub health_arg: Vec<String>,
pub load_tutor: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 24 additions & 10 deletions helix-term/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,31 @@ fn probe_treesitter_feature(lang: &str, feature: TsFeature) -> std::io::Result<(
Ok(())
}

pub fn print_health(health_arg: Option<String>) -> 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<String>) -> 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(())
}

0 comments on commit 05d1f94

Please sign in to comment.