diff options
author | Dan Davison <dandavison7@gmail.com> | 2023-07-10 10:12:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-10 10:12:07 -0400 |
commit | 8d14a1eba3ca93d6f6ebf3be541b37c6677139a6 (patch) | |
tree | a90001abda00786055ed2669c6b66f8d5d93458d | |
parent | 915662f5da4d8058c0bc6496a502c4b4ce28fe7d (diff) |
Refactor subcommand handling (#1467)
-rw-r--r-- | src/main.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs index a1f12622..ba471102 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,31 +82,24 @@ fn run_app() -> std::io::Result<i32> { assets, ); - let subcommand_result = if opt.list_languages { - Some(list_languages()) + if let Err(error) = if opt.list_languages { + list_languages() } else if opt.list_syntax_themes { - Some(subcommands::list_syntax_themes::list_syntax_themes()) + subcommands::list_syntax_themes::list_syntax_themes() } else if opt.show_syntax_themes { - Some(subcommands::show_syntax_themes::show_syntax_themes()) + subcommands::show_syntax_themes::show_syntax_themes() } else if opt.show_themes { - Some(subcommands::show_themes::show_themes( - opt.dark, - opt.light, - opt.computed.is_light_mode, - )) + subcommands::show_themes::show_themes(opt.dark, opt.light, opt.computed.is_light_mode) } else if opt.show_colors { - Some(subcommands::show_colors::show_colors()) + subcommands::show_colors::show_colors() } else if opt.parse_ansi { - Some(subcommands::parse_ansi::parse_ansi()) + subcommands::parse_ansi::parse_ansi() } else { - None - }; - if let Some(result) = subcommand_result { - if let Err(error) = result { - match error.kind() { - ErrorKind::BrokenPipe => {} - _ => fatal(format!("{error}")), - } + Ok(()) + } { + match error.kind() { + ErrorKind::BrokenPipe => {} + _ => fatal(format!("{error}")), } return Ok(0); }; @@ -114,10 +107,17 @@ fn run_app() -> std::io::Result<i32> { let _show_config = opt.show_config; let config = config::Config::from(opt); - if _show_config { + if let Err(error) = if _show_config { let stdout = io::stdout(); let mut stdout = stdout.lock(); - subcommands::show_config::show_config(&config, &mut stdout)?; + subcommands::show_config::show_config(&config, &mut stdout) + } else { + Ok(()) + } { + match error.kind() { + ErrorKind::BrokenPipe => {} + _ => fatal(format!("{error}")), + } return Ok(0); } |