From: Gunnar Wrobel Date: Thu, 16 Dec 2010 07:03:46 +0000 (+0100) Subject: Switch to modules. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ea02d9b24b15ae77d3d30f0455d840a6c8c0fcba;p=horde.git Switch to modules. --- diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli.php index 62fd7fae9..b8b56cc3c 100644 --- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli.php +++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli.php @@ -40,7 +40,7 @@ class Horde_Kolab_Cli */ static public function main(array $parameters = array()) { - $parser = self::_prepareParser($parameters); + $modular = self::_prepareModular($parameters); if (empty($parameters['output'])) { if (!class_exists('Horde_Cli')) { throw new Horde_Kolab_Cli_Exception('The Horde_Cli package seems to be missing (Class Horde_Cli is missing)!'); @@ -49,91 +49,37 @@ class Horde_Kolab_Cli } else { $cli = $parameters['output']; } + $parser = $modular->createParser(); list($options, $arguments) = $parser->parseArgs(); if (count($arguments) == 0) { $parser->printHelp(); } else { - switch ($arguments[0]) { - case 'folder': - $factory = new Horde_Kolab_Storage_Factory(); - var_dump( - $factory->createFromParams( - array( - 'driver' => $options['driver'], - 'params' => $options - ) - )->listFolders() - ); - break; - default: + try { + $modular->getProvider() + ->getModule(ucfirst($arguments[0])) + ->run($options, $arguments); + } catch (Horde_Cli_Modular_Exception $e) { $parser->printHelp(); } } } - static private function _prepareParser(array $parameters = array()) + static private function _prepareModular(array $parameters = array()) { - if (empty($parameters['parser']['class'])) { - $parser_class = 'Horde_Argv_Parser'; - } else { - $parser_class = $parameters['parser']['class']; - } - $options = array( - new Horde_Argv_Option( - '-d', - '--driver', - array( - 'action' => 'store', - 'choices' => array('horde', 'horde-php', 'php', 'pear', 'roundcube', 'mock'), - 'help' => Horde_Kolab_Cli_Translation::t( -"The Kolab backend driver that should be used. -Choices are: - - - horde [IMAP]: The Horde_Imap_Client driver as pure PHP implementation. - - horde-php [IMAP]: The Horde_Imap_Client driver based on c-client in PHP - - php [IMAP]: The PHP imap_* functions which are based on c-client - - pear [IMAP]: The PEAR-Net_IMAP driver - - roundcube [IMAP]: The roundcube IMAP driver - - mock [Memory]: A dummy driver." + return new Horde_Cli_Modular( + array( + 'parser' => array( + 'class' => empty($parameters['parser']['class']) ? 'Horde_Argv_Parser' : $parameters['parser']['class'], + 'usage' => Horde_Kolab_Cli_Translation::t( + "[options] MODULE ACTION\n\nPossible MODULEs and ACTIONs:\n\n" ) + ), + 'modules' => array( + 'directory' => dirname(__FILE__) . '/Cli/Module', + ), + 'provider' => array( + 'prefix' => 'Horde_Kolab_Cli_Module_' ) - ), - new Horde_Argv_Option( - '-u', - '--username', - array( - 'action' => 'store', - 'help' => Horde_Kolab_Cli_Translation::t('The user accessing the backend.') - ) - ), - new Horde_Argv_Option( - '-p', - '--password', - array( - 'action' => 'store', - 'help' => Horde_Kolab_Cli_Translation::t('The password of the user accessing the backend.') - ) - ), - new Horde_Argv_Option( - '-H', - '--host', - array( - 'action' => 'store', - 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.') - ) - ), - ); - $usage = Horde_Kolab_Cli_Translation::t( - "[options] MODULE ACTION\nPossible MODULEs and ACTIONs: - - folder - Handle folders. - list [default] - List the folders -" - ); - return new $parser_class( - array( - 'usage' => '%prog ' . $usage, - 'optionList' => $options ) ); } diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php new file mode 100644 index 000000000..db9b67533 --- /dev/null +++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php @@ -0,0 +1,137 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cli_Modular + */ + +/** + * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the + * Kolab CLI. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Cli_Modular + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cli_Modular + */ +class Horde_Kolab_Cli_Module_Base +implements Horde_Cli_Modular_Module +{ + /** + * Get the usage description for this module. + * + * @return string The description. + */ + public function getUsage() + { + return ''; + } + + /** + * Get a set of base options that this module adds to the CLI argument + * parser. + * + * @return array The options. + */ + public function getBaseOptions() + { + return array( + new Horde_Argv_Option( + '-d', + '--driver', + array( + 'action' => 'store', + 'choices' => array('horde', 'horde-php', 'php', 'pear', 'roundcube', 'mock'), + 'help' => Horde_Kolab_Cli_Translation::t( +"The Kolab backend driver that should be used. +Choices are: + + - horde [IMAP]: The Horde_Imap_Client driver as pure PHP implementation. + - horde-php [IMAP]: The Horde_Imap_Client driver based on c-client in PHP + - php [IMAP]: The PHP imap_* functions which are based on c-client + - pear [IMAP]: The PEAR-Net_IMAP driver + - roundcube [IMAP]: The roundcube IMAP driver + - mock [Mem.]: A dummy driver that uses memory." + ) + ) + ), + new Horde_Argv_Option( + '-u', + '--username', + array( + 'action' => 'store', + 'help' => Horde_Kolab_Cli_Translation::t('The user accessing the backend.') + ) + ), + new Horde_Argv_Option( + '-p', + '--password', + array( + 'action' => 'store', + 'help' => Horde_Kolab_Cli_Translation::t('The password of the user accessing the backend.') + ) + ), + new Horde_Argv_Option( + '-H', + '--host', + array( + 'action' => 'store', + 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.') + ) + ), + ); + } + + /** + * Indicate if the module provides an option group. + * + * @return boolean True if an option group should be added. + */ + public function hasOptionGroup() + { + return false; + } + + /** + * Return the title for the option group representing this module. + * + * @return string The group title. + */ + public function getOptionGroupTitle() + { + return ''; + } + + /** + * Return the description for the option group representing this module. + * + * @return string The group description. + */ + public function getOptionGroupDescription() + { + return ''; + } + + /** + * Return the options for this module. + * + * @return array The group options. + */ + public function getOptionGroupOptions() + { + return array(); + } +} \ No newline at end of file diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php new file mode 100644 index 000000000..b22582429 --- /dev/null +++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php @@ -0,0 +1,113 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cli_Modular + */ + +/** + * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the + * Kolab CLI. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Cli_Modular + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cli_Modular + */ +class Horde_Kolab_Cli_Module_Folder +implements Horde_Cli_Modular_Module +{ + /** + * Get the usage description for this module. + * + * @return string The description. + */ + public function getUsage() + { + return Horde_Kolab_Cli_Translation::t(" folder - Handle folders + - list [default]: List the folders in the backend +"); + } + + /** + * Get a set of base options that this module adds to the CLI argument + * parser. + * + * @return array The options. + */ + public function getBaseOptions() + { + return array(); + } + + /** + * Indicate if the module provides an option group. + * + * @return boolean True if an option group should be added. + */ + public function hasOptionGroup() + { + return false; + } + + /** + * Return the title for the option group representing this module. + * + * @return string The group title. + */ + public function getOptionGroupTitle() + { + return ''; + } + + /** + * Return the description for the option group representing this module. + * + * @return string The group description. + */ + public function getOptionGroupDescription() + { + return ''; + } + + /** + * Return the options for this module. + * + * @return array The group options. + */ + public function getOptionGroupOptions() + { + return array(); + } + + /** + * Run the module. + * + * @return NULL + */ + public function run($options, $arguments) + { + $factory = new Horde_Kolab_Storage_Factory(); + var_dump( + $factory->createFromParams( + array( + 'driver' => $options['driver'], + 'params' => $options + ) + )->listFolders() + ); + } +} \ No newline at end of file diff --git a/framework/Kolab_Cli/package.xml b/framework/Kolab_Cli/package.xml index 8a123344f..315f09f09 100644 --- a/framework/Kolab_Cli/package.xml +++ b/framework/Kolab_Cli/package.xml @@ -22,8 +22,8 @@ jan@horde.org yes - 2010-12-15 - + 2010-12-16 + 0.0.1 0.0.1 @@ -45,6 +45,10 @@ + + + + @@ -81,6 +85,14 @@ 1.9.0 + + Cli + pear.horde.org + + + Cli_Modular + pear.horde.org + @@ -88,6 +100,8 @@ + + @@ -108,7 +122,7 @@ alpha alpha - 2010-12-15 + 2010-12-16 GPL * Initial release.