From: Gunnar Wrobel Date: Wed, 29 Dec 2010 10:03:58 +0000 (+0100) Subject: Rename the 'folders' action to 'list'. Add 'type' subaction (lists all folders of... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=24ec74fd0573cab3c6909e49c046e139f8923307;p=horde.git Rename the 'folders' action to 'list'. Add 'type' subaction (lists all folders of a specific type). --- diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php deleted file mode 100644 index 750d8a535..000000000 --- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php +++ /dev/null @@ -1,175 +0,0 @@ - - * @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_Kolab_Cli_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(); - } - - /** - * Handle the options and arguments. - * - * @param mixed &$options An array of options. - * @param mixed &$arguments An array of arguments. - * - * @return NULL - */ - public function handleArguments(&$options, &$arguments) - { - } - - /** - * Run the module. - * - * @param Horde_Cli $cli The CLI handler. - * @param mixed $options An array of options. - * @param mixed $arguments An array of arguments. - * - * @return NULL - */ - public function run($cli, $options, $arguments) - { - if (!isset($arguments[1])) { - $action = 'list'; - } else { - $action = $arguments[1]; - } - switch ($action) { - case 'list': - $folders = $this->_getStorage($options)->getList()->listFolders(); - foreach ($folders as $folder) { - $cli->writeln($folder); - } - break; - case 'show': - if (!isset($arguments[2])) { - $folder_name = 'INBOX'; - } else { - $folder_name = $arguments[2]; - } - $folder = $this->_getStorage($options)->getFolder($folder_name); - $cli->writeln('Path: ' . $folder->getPath()); - $cli->writeln('Title: ' . $folder->getTitle()); - $cli->writeln('Owner: ' . $folder->getOwner()); - $cli->writeln('Type: ' . $folder->getType()); - $cli->writeln('Namespace: ' . $folder->getNamespace()); - break; - default: - $cli->message( - sprintf( - Horde_Kolab_Cli_Translation::t('Action %s not supported!'), - $action - ), - 'cli.error' - ); - break; - } - } - - /** - * Return the driver for the Kolab storage backend. - * - * @param mixed $options An array of options. - * - * @return Horde_Kolab_Storage The storage handler. - */ - private function _getStorage($options) - { - $factory = new Horde_Kolab_Storage_Factory(); - return $factory->createFromParams( - array( - 'driver' => $options['driver'], - 'params' => $options, - 'logger' => isset($options['log']) ? $options['log'] : null, - 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null, - ) - ); - } -} \ No newline at end of file diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/List.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/List.php new file mode 100644 index 000000000..9c68f5a4a --- /dev/null +++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/List.php @@ -0,0 +1,197 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Cli_Modular + */ + +/** + * The Horde_Kolab_Cli_Module_List:: handles folder lists. + * + * 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_List +implements Horde_Kolab_Cli_Module +{ + /** + * Get the usage description for this module. + * + * @return string The description. + */ + public function getUsage() + { + return Horde_Kolab_Cli_Translation::t(" list - Handle folder lists + - folders [default]: List the folders in the backend + - types : Display all folders that have a folder type. + - type TYPE : Display the folders of type TYPE. +"); + } + + /** + * 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(); + } + + /** + * Handle the options and arguments. + * + * @param mixed &$options An array of options. + * @param mixed &$arguments An array of arguments. + * + * @return NULL + */ + public function handleArguments(&$options, &$arguments) + { + } + + /** + * Run the module. + * + * @param Horde_Cli $cli The CLI handler. + * @param mixed $options An array of options. + * @param mixed $arguments An array of arguments. + * + * @return NULL + */ + public function run($cli, $options, $arguments) + { + if (!isset($arguments[1])) { + $action = 'folders'; + } else { + $action = $arguments[1]; + } + switch ($action) { + case 'folders': + $folders = $this->_getStorage($options)->getList()->listFolders(); + foreach ($folders as $folder) { + $cli->writeln($folder); + } + break; + case 'types': + $types = $this->_getStorage($options)->getList()->listTypes(); + if (!empty($types)) { + $pad = max(array_map('strlen', array_keys($types))) + 2; + foreach ($types as $folder => $type) { + $cli->writeln(Horde_String::pad($folder . ':', $pad) . $type); + } + } + break; + case 'type': + if (!isset($arguments[2])) { + throw new Horde_Kolab_Cli_Exception('You must provide a TYPE argument!'); + } + $type = $arguments[2]; + $folders = $this->_getStorage($options) + ->getList() + ->getQuery('Base') + ->listByType($type); + foreach ($folders as $folder) { + $cli->writeln($folder); + } + break; + case 'show': + if (!isset($arguments[2])) { + $folder_name = 'INBOX'; + } else { + $folder_name = $arguments[2]; + } + $folder = $this->_getStorage($options)->getFolder($folder_name); + $cli->writeln('Path: ' . $folder->getPath()); + $cli->writeln('Title: ' . $folder->getTitle()); + $cli->writeln('Owner: ' . $folder->getOwner()); + $cli->writeln('Type: ' . $folder->getType()); + $cli->writeln('Namespace: ' . $folder->getNamespace()); + break; + default: + $cli->message( + sprintf( + Horde_Kolab_Cli_Translation::t('Action %s not supported!'), + $action + ), + 'cli.error' + ); + break; + } + } + + /** + * Return the driver for the Kolab storage backend. + * + * @param mixed $options An array of options. + * + * @return Horde_Kolab_Storage The storage handler. + */ + private function _getStorage($options) + { + $factory = new Horde_Kolab_Storage_Factory(); + return $factory->createFromParams( + array( + 'driver' => $options['driver'], + 'params' => $options, + 'logger' => isset($options['log']) ? $options['log'] : null, + 'timelog' => isset($options['log']) && isset($options['timed']) ? $options['log'] : null, + ) + ); + } +} \ No newline at end of file diff --git a/framework/Kolab_Cli/package.xml b/framework/Kolab_Cli/package.xml index 62ff61fda..4c364a25a 100644 --- a/framework/Kolab_Cli/package.xml +++ b/framework/Kolab_Cli/package.xml @@ -22,8 +22,8 @@ jan@horde.org yes - 2010-12-21 - + 2010-12-29 + 0.0.1 0.0.1 @@ -47,7 +47,7 @@ - + @@ -104,6 +104,10 @@ pear.horde.org + Util + pear.horde.org + + Log pear.horde.org @@ -116,7 +120,7 @@ - + @@ -138,7 +142,7 @@ alpha alpha - 2010-12-21 + 2010-12-29 GPL * Initial release.