diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-22 21:54:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-22 21:54:20 +0900 |
| commit | ca571851e4c3e08a2e3ae22f8119ab6446abbb1b (patch) | |
| tree | 1fbebb43d0285dcd3095e272b0dc81c79f27a85c /crates/mozart/src | |
| parent | 23356a21acee0fa78df2c09847e14f463666462d (diff) | |
| download | php-mozart-ca571851e4c3e08a2e3ae22f8119ab6446abbb1b.tar.gz php-mozart-ca571851e4c3e08a2e3ae22f8119ab6446abbb1b.tar.zst php-mozart-ca571851e4c3e08a2e3ae22f8119ab6446abbb1b.zip | |
fix(depends): align exit codes and error messages with Composer
Return exit code 1 when no dependents are found or no packages are
installed, matching Composer's behavior. Align error messages: use
"Could not find package" and "There is no installed package depending
on" phrasing. Write errors to stderr instead of stdout. Apply the
same no-install fix to the prohibits command.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src')
| -rw-r--r-- | crates/mozart/src/commands/depends.rs | 23 | ||||
| -rw-r--r-- | crates/mozart/src/commands/prohibits.rs | 11 |
2 files changed, 23 insertions, 11 deletions
diff --git a/crates/mozart/src/commands/depends.rs b/crates/mozart/src/commands/depends.rs index 7e7ad70..673fd35 100644 --- a/crates/mozart/src/commands/depends.rs +++ b/crates/mozart/src/commands/depends.rs @@ -22,7 +22,7 @@ pub struct DependsArgs { pub async fn execute( args: &DependsArgs, cli: &super::Cli, - _console: &mozart_core::console::Console, + console: &mozart_core::console::Console, ) -> anyhow::Result<()> { let working_dir = match &cli.working_dir { Some(dir) => PathBuf::from(dir), @@ -32,11 +32,12 @@ pub async fn execute( let packages = super::dependency::load_packages(&working_dir, args.locked)?; if packages.is_empty() { - println!( - "{}", - mozart_core::console::info("No packages found. Run `mozart install` first.") + console.write_error( + "No dependencies installed. Try running mozart install or update, or use --locked.", ); - return Ok(()); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } let target = args.package.to_lowercase(); @@ -45,7 +46,7 @@ pub async fn execute( let target_known = packages.iter().any(|p| p.name.to_lowercase() == target); if !target_known { anyhow::bail!( - "Package '{}' not found in the dependency graph.", + "Could not find package \"{}\" in your project", args.package ); } @@ -54,6 +55,16 @@ pub async fn execute( let needles = vec![target]; let results = super::dependency::get_dependents(&packages, &needles, None, false, recursive)?; + if results.is_empty() { + eprintln!( + "There is no installed package depending on \"{}\"", + args.package + ); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); + } + if args.tree { super::dependency::print_tree(&results, 0); } else { diff --git a/crates/mozart/src/commands/prohibits.rs b/crates/mozart/src/commands/prohibits.rs index ca3bc35..a6a70d5 100644 --- a/crates/mozart/src/commands/prohibits.rs +++ b/crates/mozart/src/commands/prohibits.rs @@ -25,7 +25,7 @@ pub struct ProhibitsArgs { pub async fn execute( args: &ProhibitsArgs, cli: &super::Cli, - _console: &mozart_core::console::Console, + console: &mozart_core::console::Console, ) -> anyhow::Result<()> { let working_dir = match &cli.working_dir { Some(dir) => PathBuf::from(dir), @@ -35,11 +35,12 @@ pub async fn execute( let packages = super::dependency::load_packages(&working_dir, args.locked)?; if packages.is_empty() { - println!( - "{}", - mozart_core::console::info("No packages found. Run `mozart install` first.") + console.write_error( + "No dependencies installed. Try running mozart install or update, or use --locked.", ); - return Ok(()); + return Err(mozart_core::exit_code::bail_silent( + mozart_core::exit_code::GENERAL_ERROR, + )); } // Parse the version constraint the user is asking about |
