svn: /pear2/Pyrus/trunk/ data/built-in-commands.xml src/Pyrus/ScriptFrontend/Commands.php

From: Date: Thu, 03 Dec 2009 19:45:51 +0000
Subject: svn: /pear2/Pyrus/trunk/ data/built-in-commands.xml src/Pyrus/ScriptFrontend/Commands.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-9067@lists.php.net to get a copy of this message
saltybeagle Thu, 03 Dec 2009 19:45:51 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=291667 Log: Add get command to retrieve a single configuration variable. Still need a -q --quiet option to reduce the noise so something like this can be used pyrus get cache_dir Changed paths: U pear2/Pyrus/trunk/data/built-in-commands.xml U pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php Modified: pear2/Pyrus/trunk/data/built-in-commands.xml =================================================================== --- pear2/Pyrus/trunk/data/built-in-commands.xml 2009-12-03 19:44:01 UTC (rev 291666) +++ pear2/Pyrus/trunk/data/built-in-commands.xml 2009-12-03 19:45:51 UTC (rev 291667) @@ -479,6 +479,33 @@ php pyrus.phar set download_dir /home/blah/downloads</doc> </command> <command> + <name>get</name> + <class>pear2\Pyrus\ScriptFrontend\Commands</class> + <function>get</function> + <summary>Get a configuration value</summary> + <shortcut>get</shortcut> + <options> + <option> + <name>plugin</name> + <shortopt>p</shortopt> + <type><bool/></type> + <doc>Get plugin configuration only</doc> + </option> + </options> + <arguments> + <argument> + <name>variable</name> + <multiple>0</multiple> + <optional>0</optional> + <doc>Configuration variable name. This can be a system or user variable.</doc> + </argument> + </arguments> + <doc>Get a configuration variable. + +For example: +php pyrus.phar get download_dir</doc> + </command> + <command> <name>mypear</name> <class>pear2\Pyrus\ScriptFrontend\Commands</class> <function>mypear</function> Modified: pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php =================================================================== --- pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php 2009-12-03 19:44:01 UTC (rev 291666) +++ pear2/Pyrus/trunk/src/Pyrus/ScriptFrontend/Commands.php 2009-12-03 19:45:51 UTC (rev 291667) @@ -761,6 +761,29 @@ echo " $var => " . $conf->$var . "\n"; } } + + /** + * Get a configuration option. + * + * @param array $args + */ + function get($args, $options) + { + $conf = $current = \pear2\Pyrus\Config::current(); + if ($options['plugin']) { + $conf = \pear2\Pyrus\Config::singleton(\pear2\Pyrus\Config::current()->plugins_dir); + } + if (in_array($args['variable'], $conf->uservars) + || in_array($args['variable'], $conf->systemvars)) { + echo $conf->{$args['variable']} . PHP_EOL; + } else { + echo "Unknown config variable: $args[variable]\n"; + exit -1; + } + if ($options['plugin']) { + \pear2\Pyrus\Config::setCurrent($current->path); + } + } /** * Set a configuration option.

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