aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-22 21:44:52 +0900
committernsfisis <nsfisis@gmail.com>2026-02-22 21:44:52 +0900
commit23356a21acee0fa78df2c09847e14f463666462d (patch)
tree08113ca75d4748a44b4cafe4318edaaf070c49e6 /crates/mozart/src/commands
parentb6347171c9ceaf508d28ffd40fac241970a1c981 (diff)
downloadphp-mozart-23356a21acee0fa78df2c09847e14f463666462d.tar.gz
php-mozart-23356a21acee0fa78df2c09847e14f463666462d.tar.zst
php-mozart-23356a21acee0fa78df2c09847e14f463666462d.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands')
-rw-r--r--crates/mozart/src/commands/search.rs18
1 files changed, 16 insertions, 2 deletions
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<SearchResult> = results.into_iter().cloned().collect();