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