From b71466f9a40ce767cb07d80799bd12e4e8a3a122 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 20 Dec 2010 22:06:16 +0100 Subject: [PATCH] Flesh out the first cli actions. --- .../lib/Horde/Kolab/Cli/Module/Folder.php | 64 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php index b22582429..ded4f61f1 100644 --- a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php +++ b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php @@ -96,18 +96,66 @@ implements Horde_Cli_Modular_Module /** * 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($options, $arguments) + 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(); - var_dump( - $factory->createFromParams( - array( - 'driver' => $options['driver'], - 'params' => $options - ) - )->listFolders() + return $factory->createFromParams( + array( + 'driver' => $options['driver'], + 'params' => $options + ) ); } } \ No newline at end of file -- 2.11.0