]> granicus.if.org Git - php/commitdiff
* added "cvstag" command
authorStig Bakken <ssb@php.net>
Sun, 7 Apr 2002 19:42:05 +0000 (19:42 +0000)
committerStig Bakken <ssb@php.net>
Sun, 7 Apr 2002 19:42:05 +0000 (19:42 +0000)
pear/PEAR/Command/Package.php
pear/PEAR/Frontend/CLI.php
pear/PEAR/Packager.php

index f82efb2473c8589cf6d61e2de055a012decce812..cae9faffd76a866f0c32cb6fa729ae68988e2010 100644 (file)
@@ -38,6 +38,26 @@ class PEAR_Command_Package extends PEAR_Command_Common
 
     // }}}
 
+    // {{{ _displayValidationResults()
+
+    function _displayValidationResults($err, $warn, $strict = false)
+    {
+        foreach ($err as $e) {
+            $this->ui->displayLine("Error: $e");
+        }
+        foreach ($warn as $w) {
+            $this->ui->displayLine("Warning: $w");
+        }
+        $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)',
+                                       sizeof($err), sizeof($warn)));
+        if ($strict && sizeof($err) > 0) {
+            $this->ui->displayLine("Fix these errors and try again.");
+            return false;
+        }
+        return true;
+    }
+
+    // }}}
     // {{{ getCommands()
 
     /**
@@ -50,11 +70,19 @@ class PEAR_Command_Package extends PEAR_Command_Common
         return array('package',
                      'package-info',
                      'package-list',
-                     'package-validate');
+                     'package-validate',
+                     'cvstag');
     }
 
     // }}}
+    // {{{ getOptions()
 
+    function getOptions()
+    {
+        return array('Z', 'n' /*, 'f', 'd', 'q', 'Q'*/);
+    }
+
+    // }}}
     // {{{ getHelp()
 
     function getHelp($command)
@@ -73,11 +101,13 @@ class PEAR_Command_Package extends PEAR_Command_Common
             case 'package-validate':
                 return array('<package.(tgz|tar|xml)>',
                              'Verifies a package or description file');
+            case 'cvstag':
+                return array('<package.xml>',
+                             'Runs "cvs tag" on files contained in a release');
         }
     }
 
     // }}}
-
     // {{{ run()
 
     /**
@@ -109,19 +139,11 @@ class PEAR_Command_Package extends PEAR_Command_Common
                 $packager->debug = $this->config->get('verbose');
                 $err = $warn = array();
                 $packager->validatePackageInfo($pkginfofile, $err, $warn);
-                foreach ($err as $e) {
-                    $this->ui->displayLine("Error: $e");
-                }
-                foreach ($warn as $w) {
-                    $this->ui->displayLine("Warning: $w");
-                }
-                $this->ui->displayLine(sprintf('%d error(s), %d warning(s)',
-                                               sizeof($err), sizeof($warn)));
-                if (sizeof($err) > 0) {
-                    $this->ui->displayLine("Fix these errors and try again.");
+                if (!$this->_displayValidationResults($err, $warn, true)) {
                     break;
                 }
-                $result = $packager->Package($pkginfofile);
+                $compress = empty($options['Z']) ? true : false;
+                $result = $packager->Package($pkginfofile, $compress);
                 $output = ob_get_contents();
                 ob_end_clean();
                 $lines = explode("\n", $output);
@@ -129,9 +151,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
                     $this->ui->displayLine($line);
                 }
                 if (PEAR::isError($result)) {
-                    $this->ui->displayLine("Package failed!");
-                } else {
-                    $this->ui->displayLine("Package ok.");
+                    $this->ui->displayLine("Package failed: ".$result->getMessage());
                 }
                 break;
             }
@@ -271,7 +291,6 @@ class PEAR_Command_Package extends PEAR_Command_Common
                 }
                 $obj = new PEAR_Common;
                 $info = null;
-                $validate_result = $obj->validatePackageInfo($info, $err, $warn);
                 if (file_exists($params[0])) {
                     $fp = fopen($params[0], "r");
                     $test = fread($fp, 5);
@@ -286,14 +305,63 @@ class PEAR_Command_Package extends PEAR_Command_Common
                 if (PEAR::isError($info)) {
                     return $this->raiseError($info);
                 }
-                foreach ($err as $e) {
-                    $this->ui->displayLine("Error: $e");
+                $obj->validatePackageInfo($info, $err, $warn);
+                $this->_displayValidationResults($err, $warn);
+                break;
+            }
+
+            // }}}
+            // {{{ cvstag
+
+            case 'cvstag': {
+                if (sizeof($params) < 1) {
+                    $help = $this->getHelp($command);
+                    return $this->raiseError("$command: missing parameter: $help[0]");
+                }
+                $obj = new PEAR_Common;
+                $info = $obj->infoFromDescriptionFile($params[0]);
+                if (PEAR::isError($info)) {
+                    return $this->raiseError($info);
                 }
-                foreach ($warn as $w) {
-                    $this->ui->displayLine("Warning: $w");
+                $err = $warn = array();
+                $obj->validatePackageInfo($info, $err, $warn);
+                if (!$this->_displayValidationResults($err, $warn, true)) {
+                    break;
+                }
+                $version = $info['version'];
+                $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
+                $cvstag = "RELEASE_$cvsversion";
+                $files = array_keys($info['filelist']);
+                $command = "cvs";
+                /* until the getopt bug is fixed, these won't work:
+                if (isset($options['q'])) {
+                    $command .= ' -q';
+                }
+                if (isset($options['Q'])) {
+                    $command .= ' -Q';
+                }
+                */
+                $command .= ' tag';
+                if (isset($options['f'])) {
+                    $command .= ' -f';
+                }
+                /* neither will this one:
+                if (isset($options['d'])) {
+                    $command .= ' -d';
+                }
+                */
+                $command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
+                foreach ($files as $file) {
+                    $command .= ' ' . escapeshellarg($file);
+                }
+                $this->ui->displayLine("+ $command");
+                if (empty($options['n'])) {
+                    $fp = popen($command, "r");
+                    while ($line = fgets($fp, 1024)) {
+                        $this->ui->displayLine(rtrim($line));
+                    }
+                    pclose($fp);
                 }
-                $this->ui->displayLine(sprintf('%d error(s), %d warning(s)',
-                                               sizeof($err), sizeof($warn)));
                 break;
             }
 
index 193c2749ff66c7fd952a51a41aa0c9980f2efa78..e8cc5e49e483928329b32f3ddb74ebcb3c1314b2 100644 (file)
@@ -31,6 +31,7 @@ class PEAR_Frontend_CLI extends PEAR
      * @access public
      */
     var $type = 'CLI';
+    var $lp = ''; // line prefix
 
     var $omode = 'plain';
     var $params = array();
@@ -63,16 +64,11 @@ class PEAR_Frontend_CLI extends PEAR
 
     // }}}
 
-    // For now, all the display functions print a "| " at the
-    // beginning of the line.  This is just a temporary thing, it
-    // is for discovering commands that use print instead of
-    // the UI layer.
-
     // {{{ displayLine(text)
 
     function displayLine($text)
     {
-        print "$text\n";
+        print "$this->lp$text\n";
     }
 
     // }}}
@@ -97,8 +93,8 @@ class PEAR_Frontend_CLI extends PEAR
 
     function displayHeading($title)
     {
-        print "| ".$this->bold($title)."\n";
-        print "| ".str_repeat("=", strlen($title))."\n";
+        print $this->lp.$this->bold($title)."\n";
+        print $this->lp.str_repeat("=", strlen($title))."\n";
     }
 
     // }}}
@@ -109,7 +105,7 @@ class PEAR_Frontend_CLI extends PEAR
         if ($type == 'password') {
             system('stty -echo');
         }
-        print "$prompt ";
+        print "$this->lp$prompt ";
         if ($default) {
             print "[$default] ";
         }
@@ -134,7 +130,7 @@ class PEAR_Frontend_CLI extends PEAR
     {
         static $positives = array('y', 'yes', 'on', '1');
         static $negatives = array('n', 'no', 'off', '0');
-        print "$prompt [$default] : ";
+        print "$this->lp$prompt [$default] : ";
         $fp = fopen("php://stdin", "r");
         $line = fgets($fp, 2048);
         fclose($fp);
index ce4ee49667b8d473fd1b1c335d538c8e75ed7043..b471cf1eef653c683b5663db79fed760c5a6fd6a 100644 (file)
@@ -137,7 +137,8 @@ class PEAR_Packager extends PEAR_Common
         $this->log(1, "Package $dest_package done");
         $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkgversion);
         $cvstag = "RELEASE_$cvsversion";
-        $this->log(0, "Tag the released code with: cvs tag $cvstag");
+        $this->log(0, "Tag the released code with `pear cvstag'");
+        $this->log(0, "(or set the CVS tag $cvstag by hand)");
         return $dest_package;
     }