From d9cc83f4e775ed7f59cf21f350b2140c29cf6b07 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Feb 2026 13:52:08 +0900 Subject: refactor(cli): replace std::process::exit() with bail_silent in command handlers Improves testability and ensures proper resource cleanup by returning errors through the existing MozartError/exit_code mechanism instead of terminating the process directly. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/commands/audit.rs | 2 +- crates/mozart/src/commands/browse.rs | 3 ++- crates/mozart/src/commands/check_platform_reqs.rs | 2 +- crates/mozart/src/commands/config.rs | 4 +++- crates/mozart/src/commands/dump_autoload.rs | 2 +- crates/mozart/src/commands/reinstall.rs | 4 +++- crates/mozart/src/commands/search.rs | 4 +++- 7 files changed, 14 insertions(+), 7 deletions(-) (limited to 'crates/mozart/src/commands') diff --git a/crates/mozart/src/commands/audit.rs b/crates/mozart/src/commands/audit.rs index 70c4400..5dc602a 100644 --- a/crates/mozart/src/commands/audit.rs +++ b/crates/mozart/src/commands/audit.rs @@ -162,7 +162,7 @@ pub async fn execute( }; if exit_code != 0 { - std::process::exit(exit_code); + return Err(mozart_core::exit_code::bail_silent(exit_code)); } Ok(()) diff --git a/crates/mozart/src/commands/browse.rs b/crates/mozart/src/commands/browse.rs index a88e503..3946acd 100644 --- a/crates/mozart/src/commands/browse.rs +++ b/crates/mozart/src/commands/browse.rs @@ -1,5 +1,6 @@ use clap::Args; use mozart_core::console_format; +use mozart_core::exit_code; use std::path::{Path, PathBuf}; use std::process::Command; @@ -78,7 +79,7 @@ pub async fn execute( } if exit_code != 0 { - std::process::exit(exit_code); + return Err(exit_code::bail_silent(exit_code)); } Ok(()) diff --git a/crates/mozart/src/commands/check_platform_reqs.rs b/crates/mozart/src/commands/check_platform_reqs.rs index f8c9d72..b3197c1 100644 --- a/crates/mozart/src/commands/check_platform_reqs.rs +++ b/crates/mozart/src/commands/check_platform_reqs.rs @@ -104,7 +104,7 @@ pub async fn execute( } if exit_code != 0 { - std::process::exit(exit_code); + return Err(mozart_core::exit_code::bail_silent(exit_code)); } Ok(()) diff --git a/crates/mozart/src/commands/config.rs b/crates/mozart/src/commands/config.rs index 92f9b59..df31f8d 100644 --- a/crates/mozart/src/commands/config.rs +++ b/crates/mozart/src/commands/config.rs @@ -948,7 +948,9 @@ fn execute_read( or provide a setting key." ) ); - std::process::exit(1); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } Some(key) => { // 1. Repository query diff --git a/crates/mozart/src/commands/dump_autoload.rs b/crates/mozart/src/commands/dump_autoload.rs index ca559f8..c35690b 100644 --- a/crates/mozart/src/commands/dump_autoload.rs +++ b/crates/mozart/src/commands/dump_autoload.rs @@ -157,7 +157,7 @@ pub async fn execute( } if args.strict_ambiguous && result.has_ambiguous_classes { - std::process::exit(2); + return Err(mozart_core::exit_code::bail_silent(2)); } Ok(()) diff --git a/crates/mozart/src/commands/reinstall.rs b/crates/mozart/src/commands/reinstall.rs index 1665786..b38d9f7 100644 --- a/crates/mozart/src/commands/reinstall.rs +++ b/crates/mozart/src/commands/reinstall.rs @@ -153,7 +153,9 @@ pub async fn execute( if selected.is_empty() { eprintln!("Found no packages to reinstall, aborting."); - std::process::exit(1); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } // Step 6: For each selected package, find its locked metadata. diff --git a/crates/mozart/src/commands/search.rs b/crates/mozart/src/commands/search.rs index 6da85f9..d7be821 100644 --- a/crates/mozart/src/commands/search.rs +++ b/crates/mozart/src/commands/search.rs @@ -121,7 +121,9 @@ pub async fn execute( "Unsupported format \"{format}\". See help for supported formats." ) ); - std::process::exit(1); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } let (all_results, _total) = -- cgit v1.3.1