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

From: Date: Mon, 01 Nov 2004 18:10:10 +0000
Subject: cvs: pear-core /PEAR/Command Config.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-1205@lists.php.net to get a copy of this message
cellog Mon Nov 1 13:10:10 2004 EDT Modified files: /pear-core/PEAR/Command Config.php Log: add config-create command to auto-generate a default configuration file http://cvs.php.net/diff.php/pear-core/PEAR/Command/Config.php?r1=1.29&r2=1.30&ty=u Index: pear-core/PEAR/Command/Config.php diff -u pear-core/PEAR/Command/Config.php:1.29 pear-core/PEAR/Command/Config.php:1.30 --- pear-core/PEAR/Command/Config.php:1.29 Sat Aug 14 10:15:22 2004 +++ pear-core/PEAR/Command/Config.php Mon Nov 1 13:10:08 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Config.php,v 1.29 2004/08/14 14:15:22 cellog Exp $ +// $Id: Config.php,v 1.30 2004/11/01 18:10:08 cellog Exp $ require_once "PEAR/Command/Common.php"; require_once "PEAR/Config.php"; @@ -86,6 +86,19 @@ displays help for all configuration parameters. ', ), + 'config-create' => array( + 'summary' => 'Create a Default configuration file', + 'function' => 'doConfigCreate', + 'shortcut' => 'cc', + 'options' => array(), + 'doc' => '<root path> <filename> +Create a default configuration file with all directory configuration +variables set to subdirectories of <root path>, and save it as <filename>. +This is useful especially for creating a configuration file for a remote +PEAR installation (using the --remoteconfig option of install, upgrade, +and uninstall). +', + ), ); // }}} @@ -209,6 +222,50 @@ } // }}} + // {{{ doConfigCreate() + + function doConfigCreate($command, $options, $params) + { + if (count($params) != 2) { + return PEAR::raiseError('There must be two parameters, root path and filename, for ' . + 'config-create'); + } + if (!file_exists($params[1])) { + if (!@touch($params[1])) { + return PEAR::raiseError('Could not create "' . $params[1] . '"'); + } + } + $params[1] = realpath($params[1]); + $config = &new PEAR_Config($params[1]); + $root = $params[0]; + // Clean up the DIRECTORY_SEPARATOR mess + $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; + $root = preg_replace(array('!\\+!', '!/+!', "!$ds2+!"), + '/', + $root); + if ($root{0} != '/') { + return PEAR::raiseError('Root directory must be an absolute path beginning with "/", ' . + 'was: "' . $root . '"'); + } + if ($root{strlen($root) - 1} == '/') { + $root = substr($root, 0, strlen($root) - 1); + } + $config->set('php_dir', "$root/pear/php"); + $config->set('data_dir', "$root/pear/data"); + $config->set('ext_dir', "$root/pear/ext"); + $config->set('doc_dir', "$root/pear/docs"); + $config->set('test_dir', "$root/pear/tests"); + $config->set('cache_dir', "$root/pear/cache"); + $config->set('bin_dir', "$root/pear"); + $save = $this->config; + $this->config = $config; + $this->doConfigShow('config-show', array(), array('user')); + $this->config = $save; + $this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"', + $command); + } + + // }}} // {{{ _checkLayer() /**

« previous php.pear.core (#1205) next »