From: Stig Bakken Date: Sun, 7 Apr 2002 19:42:05 +0000 (+0000) Subject: * added "cvstag" command X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~812 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6303972256ca0b5c296dc3fbafd7da85fbf92885;p=php * added "cvstag" command --- diff --git a/pear/PEAR/Command/Package.php b/pear/PEAR/Command/Package.php index f82efb2473..cae9faffd7 100644 --- a/pear/PEAR/Command/Package.php +++ b/pear/PEAR/Command/Package.php @@ -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('', 'Verifies a package or description file'); + case 'cvstag': + return array('', + '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; } diff --git a/pear/PEAR/Frontend/CLI.php b/pear/PEAR/Frontend/CLI.php index 193c2749ff..e8cc5e49e4 100644 --- a/pear/PEAR/Frontend/CLI.php +++ b/pear/PEAR/Frontend/CLI.php @@ -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); diff --git a/pear/PEAR/Packager.php b/pear/PEAR/Packager.php index ce4ee49667..b471cf1eef 100644 --- a/pear/PEAR/Packager.php +++ b/pear/PEAR/Packager.php @@ -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; }