cvs: pear-core /PEAR/Command Config.php

From: Date: Mon, 15 Nov 2004 21:40:17 +0000
Subject: cvs: pear-core /PEAR/Command Config.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-25992@lists.php.net to get a copy of this message
cellog Mon Nov 15 16:40:17 2004 EDT Modified files: /pear-core/PEAR/Command Config.php Log: add short option to manipulate config for a specific channel without having to set default_channel http://cvs.php.net/diff.php/pear-core/PEAR/Command/Config.php?r1=1.30&r2=1.31&ty=u Index: pear-core/PEAR/Command/Config.php diff -u pear-core/PEAR/Command/Config.php:1.30 pear-core/PEAR/Command/Config.php:1.31 --- pear-core/PEAR/Command/Config.php:1.30 Mon Nov 1 13:10:08 2004 +++ pear-core/PEAR/Command/Config.php Mon Nov 15 16:40:11 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Config.php,v 1.30 2004/11/01 18:10:08 cellog Exp $ +// $Id: Config.php,v 1.31 2004/11/15 21:40:11 cellog Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Config.php"; @@ -36,7 +36,13 @@ 'summary' => 'Show All Settings', 'function' => 'doConfigShow', 'shortcut' => 'csh', - 'options' => array(), + 'options' => array( + 'channel' => array( + 'shortopt' => 'c', + 'doc' => 'show configuration variables for another channel', + 'arg' => 'CHAN', + ), +), 'doc' => '[layer] Displays all configuration values. An optional argument may be used to tell which configuration layer to display. Valid @@ -49,7 +55,13 @@ 'summary' => 'Show One Setting', 'function' => 'doConfigGet', 'shortcut' => 'cg', - 'options' => array(), + 'options' => array( + 'channel' => array( + 'shortopt' => 'c', + 'doc' => 'show configuration variables for another channel', + 'arg' => 'CHAN', + ), +), 'doc' => '<parameter> [layer] Displays the value of one configuration parameter. The first argument is the name of the parameter, an optional second argument @@ -64,7 +76,13 @@ 'summary' => 'Change Setting', 'function' => 'doConfigSet', 'shortcut' => 'cs', - 'options' => array(), + 'options' => array( + 'channel' => array( + 'shortopt' => 'c', + 'doc' => 'show configuration variables for another channel', + 'arg' => 'CHAN', + ), +), 'doc' => '<parameter> <value> [layer] Sets the value of one configuration parameter. The first argument is the name of the parameter, the second argument is the new value. Some @@ -126,10 +144,16 @@ } $keys = $this->config->getKeys(); sort($keys); - $data = array('caption' => 'Configuration (channel ' . $this->config->get('default_channel') . '):'); + $channel = isset($options['channel']) ? $options['channel'] : + $this->config->get('default_channel'); + $reg = &$this->config->getRegistry(); + if (!$reg->channelExists($channel)) { + return $this->raiseError('Channel "' . $channel . '" does not exist'); + } + $data = array('caption' => 'Configuration (channel ' . $channel . '):'); foreach ($keys as $key) { $type = $this->config->getType($key); - $value = $this->config->get($key, @$params[0]); + $value = $this->config->get($key, @$params[0], $channel); if ($type == 'password' && $value) { $value = '********'; } @@ -158,12 +182,18 @@ if ($error = $this->_checkLayer(@$params[1])) { return $this->raiseError($error); } + $channel = isset($options['channel']) ? $options['channel'] : + $this->config->get('default_channel'); + $reg = &$this->config->getRegistry(); + if (!$reg->channelExists($channel)) { + return $this->raiseError('Channel "' . $channel . '" does not exist'); + } if (sizeof($params) < 1 || sizeof($params) > 2) { return $this->raiseError("config-get expects 1 or 2 parameters"); } elseif (sizeof($params) == 1) { - $this->ui->outputData($this->config->get($params[0]), $command); + $this->ui->outputData($this->config->get($params[0]), $command, $channel); } else { - $data = $this->config->get($params[0], $params[1]); + $data = $this->config->get($params[0], $params[1], $channel); $this->ui->outputData($data, $command); } return true; @@ -186,9 +216,17 @@ $failmsg .= $error; return PEAR::raiseError($failmsg); } + $channel = isset($options['channel']) ? $options['channel'] : + $this->config->get('default_channel'); + $reg = &$this->config->getRegistry(); + if (!$reg->channelExists($channel)) { + return $this->raiseError('Channel "' . $channel . '" does not exist'); + } + array_push($params, $channel); if (!call_user_func_array(array(&$this->config, 'set'), $params)) { - $failmsg = "config-set (" . implode(", ", $params) . ") failed"; + array_pop($params); + $failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel"; } else { $this->config->store(); }

« previous php.pear.cvs (#25992) next »