From d829063e596c6fffc4c30fb30f6d462ac9ba2928 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 24 Mar 2015 20:49:27 +0100 Subject: [PATCH] consistent exit codes --- bin/pharext | Bin 64896 -> 65445 bytes src/pharext/Command.php | 21 +++++++ src/pharext/Installer.php | 126 ++++++++++++++++++++------------------ src/pharext/Packager.php | 13 ++-- 4 files changed, 95 insertions(+), 65 deletions(-) diff --git a/bin/pharext b/bin/pharext index ec47e3a14a1c8cfa244ec1c50c919297e7060920..911b258b1f47e349d06b92667419046624737b15 100755 GIT binary patch delta 1267 zcmZuvTWAwe5KXLFH}w&1qixgT&1N?-k!J17N`sFi#x%{^)HX%Yimq|fgr-T{-Ktfp zqKM#!Rt7<#s0jTMMO}Xct&b1&Lr~FwAJhjZXhEo8px(P1AxZs8?03o7 zbji(|XjXn4Zlg5>zM(n-R-1=F#J1ARR~iiY@x?s^$DjQA2syR_cn4L*b&Bz{Czs5< zUZgV!c3oE8+#SWeb*^0Q%_FYnAHSEm}UY`nMMM69qL)_lwdW_QC6$|oYi#G ztjoN3w%$3xPs-k2SmR)ce3!#*b}!d+1V1$U0&r2!J#=t{GU?D<7$@;mV@{{FRFQ_z zVG{*Ieg;PUE8&UX4qyBTN&`-)3wU5V{!RrNC~DY5X@Bq_;HaXQbV^osFu9~4?L=!4 zqlg1JuL=9)1J$(@lgwuOwQw>e*R3Nbd4(o%dEtGqvqBcriPqL&a9ga)7l^sM*n3!Q z*f?!0D`b3Kp>FtkwOZvj%`?^%1$8d2ME&i2XQ&p2LUy>}TUxtEi1)i(WFYcm;zBx2 zLMs>rHv&VSJg}SR7W`ueZ$dV<;6+i1tRxEYB+|P@f{e5oHA^tJZGxUQ8uqu@;R43H zZ9JThb}cOUg*&=qKAwkH&n#dGdrcgN@Iy--5>1ecEQ7=0C2%IZwGRa`$ik}VDiESg&@{Ci-tO|i zkpr~a+j;uLQJ>T|I3Q*eBuY|NGEvCQnJC<=te_y-4_OUq(>y$TJDL!=VneHjNsK1i^!fB*YbNFq6Xzok>-AOt?@}kuI#?%}j#A zzObO#3&zzJ_517n=HdsaCMHHo{s~NdHqC<%!Kk&ca&5H#o}_C05i^z-2xOGMd3f}* vT-`T$f6n}3waQI3&#fuHyyeBOkQ6y~{MP8%Vc)%T`8$=f3`CF`( delta 849 zcmXw$VMr5U7{_-TYB$Wb+7joqyW4x4F5TF4DOr%)u+433nL%M?Yiw;g-LacgiYS!y zG3y~JN-?4$Lb5LU@2!$wby6q=gSVlnTPG z>6SOJgbeVWH4=w4wuOMAI;=sa~hr z7h#<>z>1}ccWOZwK=8EP2%UlLyHO&Z&7O@X z`s+|3oe^a@Jqk+!7B&O5U<&%+bdZJdAP4s`7lI+Mz0<)&XPcprzsQW>Mzqt(;6Ixg zPHJh0hAZ_-z&IR^lY<;_g!Rr7Wi*}u7lA8ghM8Zb6x7qL+^^mN3^ z+{$94tC3Y|C%yaaKB{RcSg73BZ` diff --git a/src/pharext/Command.php b/src/pharext/Command.php index 61b8810..7664a35 100644 --- a/src/pharext/Command.php +++ b/src/pharext/Command.php @@ -7,6 +7,27 @@ namespace pharext; */ interface Command { + /** + * Argument error + */ + const EARGS = 1; + /** + * Build error + */ + const EBUILD = 2; + /** + * Signature error + */ + const ESIGN = 3; + /** + * Extract/unpack error + */ + const EEXTRACT = 4; + /** + * Install error + */ + const EINSTALL = 5; + /** * Retrieve command line arguments * @return pharext\CliArgs diff --git a/src/pharext/Installer.php b/src/pharext/Installer.php index b470c3a..83a40ad 100644 --- a/src/pharext/Installer.php +++ b/src/pharext/Installer.php @@ -76,22 +76,27 @@ class Installer implements Command * @see \pharext\Command::run() */ public function run($argc, array $argv) { - $list = new SplObjectStorage(); - $phar = new Phar(Phar::running(false)); - $temp = $this->extract($phar); - - foreach ($phar as $entry) { - $dep_file = $entry->getBaseName(); - if (fnmatch("*.ext.phar*", $dep_file)) { - $dep_phar = new Phar("$temp/$dep_file"); - $list[$dep_phar] = $this->extract($dep_phar); + try { + $list = new SplObjectStorage(); + $phar = new Phar(Phar::running(false)); + $temp = $this->extract($phar); + + foreach ($phar as $entry) { + $dep_file = $entry->getBaseName(); + if (fnmatch("*.ext.phar*", $dep_file)) { + $dep_phar = new Phar("$temp/$dep_file"); + $list[$dep_phar] = $this->extract($dep_phar); + } } - } - /* the actual ext.phar at last */ - $list[$phar] = $temp; + /* the actual ext.phar at last */ + $list[$phar] = $temp; - /* installer hooks */ - $hook = $this->hooks($list); + /* installer hooks */ + $hook = $this->hooks($list); + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EEXTRACT); + } /* standard arg stuff */ $errs = []; @@ -114,7 +119,7 @@ class Installer implements Command } } catch (\Exception $e) { $this->error("%s\n", $e->getMessage()); - exit(2); + exit(self::EARGS); } foreach ($this->args->validate() as $error) { @@ -131,23 +136,33 @@ class Installer implements Command if (!$this->args["quiet"]) { $this->help($prog); } - exit(1); + exit(self::EARGS); } - /* post process hooks */ - foreach ($hook as $callback) { - if (is_callable($callback)) { - $callback($this); + try { + /* post process hooks */ + foreach ($hook as $callback) { + if (is_callable($callback)) { + $callback($this); + } } + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EARGS); } /* install packages */ - foreach ($list as $phar) { - $this->info("Installing %s ...\n", basename($phar->getPath())); - $this->install($list[$phar]); - $this->activate($list[$phar]); - $this->cleanup($list[$phar]); - $this->info("Successfully installed %s!\n", basename($phar->getPath())); + try { + foreach ($list as $phar) { + $this->info("Installing %s ...\n", basename($phar->getPath())); + $this->install($list[$phar]); + $this->activate($list[$phar]); + $this->cleanup($list[$phar]); + $this->info("Successfully installed %s!\n", basename($phar->getPath())); + } + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EINSTALL); } } @@ -155,32 +170,26 @@ class Installer implements Command * Phpize + trinity */ private function install($temp) { - try { - // phpize - $this->info("Running phpize ...\n"); - $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"}); - $phpize->run($this->args->verbose); - - // configure - $this->info("Running configure ...\n"); - $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"}); - $configure->run($this->args->verbose); - - // make - $this->info("Running make ...\n"); - $make = new Task\Make($temp); - $make->run($this->args->verbose); - - // install - $this->info("Running make install ...\n"); - $sudo = isset($this->args->sudo) ? $this->args->sudo : null; - $install = new Task\Make($temp, ["install"], $sudo); - $install->run($this->args->verbose); - - } catch (\Exception $e) { - $this->error("%s\n", $e->getMessage()); - exit(2); - } + // phpize + $this->info("Running phpize ...\n"); + $phpize = new Task\Phpize($temp, $this->args->prefix, $this->args->{"common-name"}); + $phpize->run($this->args->verbose); + + // configure + $this->info("Running configure ...\n"); + $configure = new Task\Configure($temp, $this->args->configure, $this->args->prefix, $this->args{"common-name"}); + $configure->run($this->args->verbose); + + // make + $this->info("Running make ...\n"); + $make = new Task\Make($temp); + $make->run($this->args->verbose); + + // install + $this->info("Running make install ...\n"); + $sudo = isset($this->args->sudo) ? $this->args->sudo : null; + $install = new Task\Make($temp, ["install"], $sudo); + $install->run($this->args->verbose); } private function cleanup($temp) { @@ -202,15 +211,10 @@ class Installer implements Command $sudo = isset($this->args->sudo) ? $this->args->sudo : null; $type = $this->metadata("type") ?: "extension"; - try { - $this->info("Running INI activation ...\n"); - $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo); - if (!$activate->run($this->args->verbose)) { - $this->info("Extension already activated ...\n"); - } - } catch (\Exception $e) { - $this->error("%s\n", $e->getMessage()); - exit(3); + $this->info("Running INI activation ...\n"); + $activate = new Task\Activate($temp, $files, $type, $this->args->prefix, $this->args{"common-name"}, $sudo); + if (!$activate->run($this->args->verbose)) { + $this->info("Extension already activated ...\n"); } } } diff --git a/src/pharext/Packager.php b/src/pharext/Packager.php index efd72b6..b3be6d0 100644 --- a/src/pharext/Packager.php +++ b/src/pharext/Packager.php @@ -104,7 +104,7 @@ class Packager implements Command } } catch (\Exception $e) { $this->error("%s\n", $e->getMessage()); - exit(2); + exit(self::EARGS); } try { @@ -141,7 +141,7 @@ class Packager implements Command if (!$this->args["quiet"]) { $this->help($prog); } - exit(1); + exit(self::EARGS); } $this->createPackage(); @@ -225,7 +225,12 @@ class Packager implements Command "type" => $this->args->zend ? "zend_extension" : "extension", ]); $file = (new Task\PharBuild($this->source, $meta))->run(); + } catch (\Exception $e) { + $this->error("%s\n", $e->getMessage()); + exit(self::EBUILD); + } + try { if ($this->args->sign) { $this->info("Using private key to sign phar ...\n"); $pass = (new Task\Askpass)->run($this->args->verbose); @@ -235,7 +240,7 @@ class Packager implements Command } catch (\Exception $e) { $this->error("%s\n", $e->getMessage()); - exit(4); + exit(self::ESIGN); } if ($this->args->gzip) { @@ -286,7 +291,7 @@ class Packager implements Command } catch (\Exception $e) { $this->error("%s\n", $e->getMessage()); - exit(4); + exit(self::EBUILD); } } } -- 2.30.2