Switch to modules.
authorGunnar Wrobel <p@rdus.de>
Thu, 16 Dec 2010 07:03:46 +0000 (08:03 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 16 Dec 2010 07:07:03 +0000 (08:07 +0100)
framework/Kolab_Cli/lib/Horde/Kolab/Cli.php
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php [new file with mode: 0644]
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php [new file with mode: 0644]
framework/Kolab_Cli/package.xml

index 62fd7fa..b8b56cc 100644 (file)
@@ -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 (file)
index 0000000..db9b675
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+/**
+ * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the
+ * Kolab CLI.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Cli_Modular
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..b225824
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/**
+ * The Horde_Kolab_Cli_Module_Base:: module provides the base options of the
+ * Kolab CLI.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Cli_Modular
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
index 8a12334..315f09f 100644 (file)
@@ -22,8 +22,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-12-15</date>
- <time>06:37:46</time>
+ <date>2010-12-16</date>
+ <time>06:33:31</time>
  <version>
   <release>0.0.1</release>
   <api>0.0.1</api>
     <dir name="Horde">
      <dir name="Kolab">
       <dir name="Cli">
+       <dir name="Module">
+        <file name="Base.php" role="php" />
+        <file name="Folder.php" role="php" />
+       </dir> <!-- /lib/Horde/Kolab/Cli/Module -->
        <file name="Translation.php" role="php" />
       </dir> <!-- /lib/Horde/Kolab/Cli -->
       <file name="Cli.php" role="php" />
    <pearinstaller>
     <min>1.9.0</min>
    </pearinstaller>
+   <package>
+    <name>Cli</name>
+    <channel>pear.horde.org</channel>
+   </package>
+   <package>
+    <name>Cli_Modular</name>
+    <channel>pear.horde.org</channel>
+   </package>
   </required>
  </dependencies>
  <phprelease>
    <install as="klb" name="bin/klb" />
    <install as="Horde/Kolab/Cli.php" name="lib/Horde/Kolab/Cli.php" />
    <install as="Horde/Kolab/Cli/Translation.php" name="lib/Horde/Kolab/Cli/Translation.php" />
+   <install as="Horde/Kolab/Cli/Module/Base.php" name="lib/Horde/Kolab/Cli/Module/Base.php" />
+   <install as="Horde/Kolab/Cli/Module/Folder.php" name="lib/Horde/Kolab/Cli/Module/Folder.php" />
    <install as="Horde/Kolab/Cli/AllTests.php" name="test/Horde/Kolab/Cli/AllTests.php" />
    <install as="Horde/Kolab/Cli/Autoload.php" name="test/Horde/Kolab/Cli/Autoload.php" />
    <install as="Horde/Kolab/Cli/phpunit.xml" name="test/Horde/Kolab/Cli/phpunit.xml" />
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-12-15</date>
+   <date>2010-12-16</date>
    <license uri="http://www.gnu.org/licenses/gpl.html">GPL</license>
    <notes>
 * Initial release.