From: Gunnar Wrobel
Date: Tue, 14 Dec 2010 04:38:29 +0000 (+0100)
Subject: Add basic Cli interface.
X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9b1c4fd48fdadce7f2ca838f5c8bbb7aa039a7dc;p=horde.git
Add basic Cli interface.
---
diff --git a/framework/Kolab_Storage/bin/kolab-storage b/framework/Kolab_Storage/bin/kolab-storage
new file mode 100755
index 000000000..cce42f912
--- /dev/null
+++ b/framework/Kolab_Storage/bin/kolab-storage
@@ -0,0 +1,8 @@
+#!/usr/bin/env php
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Command line tools for Kolab storage.
+ *
+ * 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.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * @category Kolab
+ * @package Kolab_Storage
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Cli
+{
+ /**
+ * The main entry point for the application.
+ *
+ * @param array $parameters A list of named configuration parameters.
+ *
+ * 'parser' - (array) Parser configuration parameters.
+ * 'class' - (string) The class name of the parser to use.
+ * 'output' - (Horde_Cli) The output handler.
+ *
+ */
+ static public function main(array $parameters = array())
+ {
+ $parser = self::_prepareParser($parameters);
+ if (empty($parameters['output'])) {
+ if (!class_exists('Horde_Cli')) {
+ throw new Horde_Kolab_Storage_Exception('The Horde_Cli package seems to be missing (Class Horde_Cli is missing)!');
+ }
+ $cli = Horde_Cli::init();
+ } else {
+ $cli = $parameters['output'];
+ }
+ list($options, $arguments) = $parser->parseArgs();
+ $cli->message('OK');
+ }
+
+ static private function _prepareParser(array $parameters = array())
+ {
+ if (empty($parameters['parser']['class'])) {
+ $parser_class = 'Horde_Argv_Parser';
+ } else {
+ $parser_class = $parameters['parser']['class'];
+ }
+ return new $parser_class(
+ array(
+ 'usage' => '%prog ' . _("[options]")
+ )
+ );
+ }
+}
\ No newline at end of file
diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml
index 3ee19ce59..6bc8a3dc8 100644
--- a/framework/Kolab_Storage/package.xml
+++ b/framework/Kolab_Storage/package.xml
@@ -31,8 +31,8 @@
jan@horde.org
yes
- 2010-10-22
- 19:03:03
+ 2010-12-14
+ 05:23:03
0.4.0
0.1.0
@@ -126,6 +126,7 @@
+
@@ -412,17 +413,18 @@
-
+
+
+
+
-
-
-
-
-
+
+
+
@@ -520,8 +522,10 @@
+
+
@@ -663,11 +667,13 @@
-
-
-
-
+
+
+
+
+
+
@@ -738,7 +744,7 @@
alpha
alpha
- 2010-10-22
+ 2010-12-14
LGPL
* Added namespace support (Bug #6691).
diff --git a/framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php b/framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php
deleted file mode 100644
index 9dc70fbe8..000000000
--- a/framework/Kolab_Storage/script/Horde/Kolab/Storage/test_drivers.php
+++ /dev/null
@@ -1,95 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Storage
- */
-
-require_once 'Horde/Autoloader.php';
-
-/** Setup command line */
-$p = new Horde_Argv_Parser(
- array(
- 'optionList' =>
- array(
- new Horde_Argv_Option(
- '-u',
- '--user',
- array(
- 'help' => 'The user name.',
- 'type' => 'string',
- 'nargs' => 1
- )
- ),
- new Horde_Argv_Option(
- '-p',
- '--pass',
- array(
- 'help' => 'The password.',
- 'type' => 'string',
- 'nargs' => 1
- )
- ),
- new Horde_Argv_Option(
- '-H',
- '--host',
- array(
- 'help' => 'The host to connect to.',
- 'type' => 'string',
- 'nargs' => 1,
- 'default' => 'localhost'
- )
- ),
- new Horde_Argv_Option(
- '-d',
- '--debug',
- array(
- 'help' => 'The path to the IMAP client debug file.',
- 'type' => 'string',
- 'nargs' => 1
- )
- ),
- )
- )
-);
-
-/** Handle arguments */
-try {
- list($options, $args) = $p->parseArgs();
-} catch (InvalidArgumentException $e) {
- print $e->getMessage() . "\n\n" . $p->getUsage() . "\n\n";
-}
-
-/** Setup shared test fixture */
-$fixture = new stdClass;
-$fixture->conf = $options;
-$fixture->drivers = array();
-
-$all_tests = '@PHP-TEST-DIR@/Kolab_Storage/Horde/Kolab/Storage/AllTests.php';
-if (strpos($all_tests, '@PHP-TEST-DIR') !== false) {
- $all_tests = dirname(__FILE__)
- . '/../../../../test/Horde/Kolab/Storage/AllTests.php';
-}
-
-define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main');
-
-require_once $all_tests;
-
-$suite = Horde_Kolab_Storage_AllTests::suite();
-$suite->setSharedFixture($fixture);
-
-PHPUnit_TextUI_TestRunner::run($suite);
\ No newline at end of file
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CliTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CliTest.php
new file mode 100644
index 000000000..eca945dae
--- /dev/null
+++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CliTest.php
@@ -0,0 +1,53 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the CLI interface.
+ *
+ * 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 Kolab
+ * @package Kolab_Storage
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_CliTest
+extends PHPUnit_Framework_TestCase
+{
+ public function testCli()
+ {
+ $_SERVER['argv'] = array(
+ 'kolab-storage'
+ );
+ ob_start();
+ Horde_Kolab_Storage_Cli::main(
+ array(
+ 'output' => new Horde_Test_Stub_Cli(),
+ 'parser' => array('class' => 'Horde_Test_Stub_Parser')
+ )
+ );
+ $output = ob_get_contents();
+ ob_end_clean();
+ }
+}