Browse Source

Fix exit codes, cc @tyrael

Jordi Boggiano 11 years ago
parent
commit
e126c92525

+ 3 - 2
src/Composer/Command/CreateProjectCommand.php

@@ -173,8 +173,9 @@ EOT
                 $installer->disablePlugins();
             }
 
-            if (!$installer->run()) {
-                return 1;
+            $status = $installer->run();
+            if (0 !== $status) {
+                return $status;
             }
         }
 

+ 1 - 1
src/Composer/Command/InstallCommand.php

@@ -107,6 +107,6 @@ EOT
             $install->disablePlugins();
         }
 
-        return $install->run() ? 0 : 1;
+        return $install->run();
     }
 }

+ 3 - 4
src/Composer/Command/RequireCommand.php

@@ -123,14 +123,13 @@ EOT
             ->setUpdateWhitelist(array_keys($requirements));
         ;
 
-        if (!$install->run()) {
+        $status = $install->run();
+        if ($status !== 0) {
             $output->writeln("\n".'<error>Installation failed, reverting '.$file.' to its original content.</error>');
             file_put_contents($json->getPath(), $composerBackup);
-
-            return 1;
         }
 
-        return 0;
+        return $status;
     }
 
     private function updateFileCleanly($json, array $base, array $new, $requireKey)

+ 1 - 1
src/Composer/Command/UpdateCommand.php

@@ -115,6 +115,6 @@ EOT
             $install->disablePlugins();
         }
 
-        return $install->run() ? 0 : 1;
+        return $install->run();
     }
 }

+ 8 - 5
src/Composer/Installer.php

@@ -146,6 +146,8 @@ class Installer
 
     /**
      * Run installation (or update)
+     *
+     * @return int 0 on success or a positive error code on failure
      */
     public function run()
     {
@@ -205,8 +207,9 @@ class Installer
 
         try {
             $this->suggestedPackages = array();
-            if (!$this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode)) {
-                return false;
+            $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
+            if ($res !== 0) {
+                return $res;
             }
         } catch (\Exception $e) {
             $this->installationManager->notifyInstalls();
@@ -286,7 +289,7 @@ class Installer
             }
         }
 
-        return true;
+        return 0;
     }
 
     protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
@@ -448,7 +451,7 @@ class Installer
             $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
             $this->io->write($e->getMessage());
 
-            return false;
+            return max(1, $e->getCode());
         }
 
         // force dev packages to be updated if we update or install from a (potentially new) lock
@@ -533,7 +536,7 @@ class Installer
             }
         }
 
-        return true;
+        return 0;
     }
 
     /**

+ 3 - 3
tests/Composer/Test/InstallerTest.php

@@ -72,7 +72,7 @@ class InstallerTest extends TestCase
 
         $installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
         $result = $installer->run();
-        $this->assertTrue($result);
+        $this->assertSame(0, $result);
 
         $expectedInstalled   = isset($options['install']) ? $options['install'] : array();
         $expectedUpdated     = isset($options['update']) ? $options['update'] : array();
@@ -206,7 +206,7 @@ class InstallerTest extends TestCase
                 ->setDevMode($input->getOption('dev'))
                 ->setDryRun($input->getOption('dry-run'));
 
-            return $installer->run() ? 0 : 1;
+            return $installer->run();
         });
 
         $application->get('update')->setCode(function ($input, $output) use ($installer) {
@@ -217,7 +217,7 @@ class InstallerTest extends TestCase
                 ->setUpdateWhitelist($input->getArgument('packages'))
                 ->setWhitelistDependencies($input->getOption('with-dependencies'));
 
-            return $installer->run() ? 0 : 1;
+            return $installer->run();
         });
 
         if (!preg_match('{^(install|update)\b}', $run)) {