license helper
[pharext/pharext] / src / pharext / Packager.php
index 81bac81d13335cae823b9feb2a541f843a76e118..b54d2849092adf724d837fe9174b6340e790053f 100644 (file)
@@ -45,6 +45,8 @@ class Packager implements Command
                                CliArgs::REQUIRED|CliArgs::SINGLE|CliArgs::REQARG],
                        ["g", "git", "Use `git ls-tree` to determine file list",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG],
+                       ["b", "branch", "Checkout this tag/branch",
+                               CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::REQARG],
                        ["p", "pecl", "Use PECL package.xml to determine file list, name and release",
                                CliArgs::OPTIONAL|CliArgs::SINGLE|CliArgs::NOARG],
                        ["d", "dest", "Destination directory",
@@ -142,15 +144,22 @@ class Packager implements Command
         */
        private function download($source) {
                if ($this->args->git) {
-                       $task = new Task\GitClone($source);
+                       $task = new Task\GitClone($source, $this->args->branch);
                } else {
-                       $task = new Task\StreamFetch($source, function($bytes_pct) {
-                               $this->info(" %3d%% [%s>%s] \r%s",
-                                       floor($bytes_pct*100),
-                                       str_repeat("=", round(50*$bytes_pct)),
-                                       str_repeat(" ", round(50*(1-$bytes_pct))),
-                                       $bytes_pct == 1 ? "\n":""
-                               );
+                       /* print newline only once */
+                       $done = false;
+                       $task = new Task\StreamFetch($source, function($bytes_pct) use(&$done) {
+                               if (!$done) {
+                                       $this->info(" %3d%% [%s>%s] \r",
+                                               floor($bytes_pct*100),
+                                               str_repeat("=", round(50*$bytes_pct)),
+                                               str_repeat(" ", round(50*(1-$bytes_pct)))
+                                       );
+                                       if ($bytes_pct == 1) {
+                                               $done = true;
+                                               printf("\n");
+                                       }
+                               }
                        });
                }
                $local = $task->run($this->verbosity());
@@ -185,7 +194,7 @@ class Packager implements Command
         * @return string local source directory
         */
        private function localize($source) {
-               if (!stream_is_local($source)) {
+               if (!stream_is_local($source) || ($this->args->git && isset($this->args->branch))) {
                        $source = $this->download($source);
                        $this->cleanup[] = new Task\Cleanup($source);
                }
@@ -234,11 +243,10 @@ class Packager implements Command
         */
        private function createPackage() {
                try {
-                       $meta = array_merge($this->metadata(), [
-                               "date" => date("Y-m-d"),
+                       $meta = array_merge(Metadata::all(), [
                                "name" => $this->args->name,
                                "release" => $this->args->release,
-                               "license" => @file_get_contents(current(glob($this->source->getBaseDir()."/LICENSE*"))),
+                               "license" => $this->source->getLicense(),
                                "stub" => "pharext_installer.php",
                                "type" => $this->args->zend ? "zend_extension" : "extension",
                        ]);