From 23356a21acee0fa78df2c09847e14f463666462d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 22 Feb 2026 21:44:52 +0900 Subject: fix(search): validate --only-name/--only-vendor exclusivity and --format values Reject simultaneous --only-name and --only-vendor flags with an error, and reject unsupported --format values with exit code 1, matching Composer's input validation behavior. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/commands/search.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/mozart/src/commands/search.rs b/crates/mozart/src/commands/search.rs index a8edc86..f145460 100644 --- a/crates/mozart/src/commands/search.rs +++ b/crates/mozart/src/commands/search.rs @@ -64,8 +64,24 @@ pub async fn execute( _cli: &super::Cli, _console: &mozart_core::console::Console, ) -> anyhow::Result<()> { + if args.only_name && args.only_vendor { + anyhow::bail!("--only-name and --only-vendor cannot be used together"); + } + let query = args.tokens.join(" "); + let format = args.format.as_deref().unwrap_or("text"); + + if !matches!(format, "text" | "json") { + eprintln!( + "{}", + mozart_core::console::error(&format!( + "Unsupported format \"{format}\". See help for supported formats." + )) + ); + std::process::exit(1); + } + let (all_results, total) = mozart_registry::packagist::search_packages(&query, args.r#type.as_deref()).await?; @@ -81,8 +97,6 @@ pub async fn execute( } // Output - let format = args.format.as_deref().unwrap_or("text"); - match format { "json" => { let owned: Vec = results.into_iter().cloned().collect(); -- cgit v1.3.1