diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index d3b690eca..e010c122a 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -152,7 +152,23 @@ abstract class BaseDependencyCommand extends BaseCommand } if ($inverted && $input->hasArgument(self::ARGUMENT_CONSTRAINT)) { - $this->getIO()->writeError('Not finding what you were looking for? Try calling `composer update "'.$input->getArgument(self::ARGUMENT_PACKAGE).':'.$input->getArgument(self::ARGUMENT_CONSTRAINT).'" --dry-run` to get another view on the problem.'); + $composerCommand = 'update'; + + foreach ($composer->getPackage()->getRequires() as $rootRequirement) { + if ($rootRequirement->getTarget() === $needle) { + $composerCommand = 'require'; + break; + } + } + + foreach ($composer->getPackage()->getDevRequires() as $rootRequirement) { + if ($rootRequirement->getTarget() === $needle) { + $composerCommand = 'require --dev'; + break; + } + } + + $this->getIO()->writeError('Not finding what you were looking for? Try calling `composer '.$composerCommand.' "'.$needle.':'.$textConstraint.'" --dry-run` to get another view on the problem.'); } return 0; diff --git a/tests/Composer/Test/Command/BaseDependencyCommandTest.php b/tests/Composer/Test/Command/BaseDependencyCommandTest.php index 78b41d223..8b0230dfc 100644 --- a/tests/Composer/Test/Command/BaseDependencyCommandTest.php +++ b/tests/Composer/Test/Command/BaseDependencyCommandTest.php @@ -396,11 +396,11 @@ OUTPUT $secondDevNestedRequiredPackage = self::getPackage('vendor2/package3', '1.4.0'); $this->createComposerLock( - [$someRequiredPackage], + [$someRequiredPackage], [$firstDevRequiredPackage, $secondDevRequiredPackage] ); $this->createInstalledJson( - [$someRequiredPackage], + [$someRequiredPackage], [$firstDevRequiredPackage, $secondDevRequiredPackage, $secondDevNestedRequiredPackage] ); @@ -425,7 +425,7 @@ OUTPUT << 'vendor1/package1', 'version' => '^1.3'], <<