Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement modular cli and a config editing module (Request #12923).
- Loading branch information
Showing
8 changed files
with
672 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* Copyright 2013-2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL-2). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl. | ||
* | ||
* @author Ralf Lang <lang@b1-systems.de> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl LGPL-2 | ||
* @package Horde | ||
*/ | ||
|
||
|
||
if (strpos('@php_dir@', '@php_dir') === 0) { | ||
set_include_path(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path()); | ||
} | ||
|
||
$baseFile = __DIR__ . '/../lib/Application.php'; | ||
if (file_exists($baseFile)) { | ||
require_once $baseFile; | ||
} else { | ||
require_once 'PEAR/Config.php'; | ||
require_once PEAR_Config::singleton() | ||
->get('horde_dir', null, 'pear.horde.org') . '/lib/Application.php'; | ||
} | ||
Horde_Registry::appInit('horde', array('cli' => true, 'user_admin' => true)); | ||
AdminCli::main(array('cli' => $cli)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* The Cli:: class is the entry point for the various cli actions | ||
* provided by horde-cli. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Horde | ||
* @package Horde | ||
* @author Ralf Lang <lang@b1-systems.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Horde | ||
*/ | ||
|
||
/** | ||
* The AdminCli:: class is the entry point for the various cli actions | ||
* provided by horde-cli. | ||
* | ||
* Copyright 2013-2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Horde | ||
* @package Horde | ||
* @author Ralf Lang <lang@b1-systems.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Horde | ||
*/ | ||
class AdminCli | ||
{ | ||
|
||
/** | ||
* The main entry point for the application. | ||
* | ||
* @param array $parameters A list of named configuration parameters. | ||
* <pre> | ||
* 'cli' - (array) CLI configuration parameters. | ||
* 'parser' - (array) Parser configuration parameters. | ||
* 'class' - (string) The class name of the parser to use. | ||
* </pre> | ||
*/ | ||
static public function main(array $parameters = array()) | ||
{ | ||
$modular = new Horde_Cli_Modular( | ||
array( | ||
'parser' => array( | ||
'class' => empty($parameters['parser']['class']) ? 'Horde_Argv_Parser' : $parameters['parser']['class'], | ||
'usage' => "[options] [COMMAND]\n"), | ||
'modules' => array( | ||
'directory' => __DIR__ . '/AdminCli', | ||
'exclude' => 'Base' | ||
), | ||
'provider' => array('prefix' => 'AdminCli_Module_') | ||
) | ||
); | ||
$modules = $modular->getModules(); | ||
$parser = $modular->createParser(); | ||
list($options, $arguments) = $parser->parseArgs(); | ||
|
||
// get the provider by the first unparsed argument | ||
if (count($arguments) == 0) { | ||
$parser->printHelp(); | ||
exit; | ||
} | ||
$moduleName = $arguments[0]; | ||
$provider = $modular->getProvider(); | ||
try { | ||
$module = $provider->getModule($moduleName); | ||
} catch (Horde_Cli_Modular_Exception $e) { | ||
print "Invalid Module\n"; | ||
$parser->printHelp(); | ||
exit; | ||
} | ||
$module->run($parameters['cli'], $options, $arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* AdminCli_Module_Base:: provides core functionality for the | ||
* different modules. | ||
* | ||
* PHP version 5 | ||
* | ||
* @category Horde | ||
* @package Horde | ||
* @author Ralf Lang <lang@b1-systems.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Horde | ||
*/ | ||
|
||
/** | ||
* AdminCli_Module_Base:: provides core functionality for the | ||
* different modules. | ||
* | ||
* Copyright 2013-2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @category Horde | ||
* @package Horde | ||
* @author Ralf Lang <lang@b1-systems.de> | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @link http://pear.horde.org/index.php?package=Horde | ||
*/ | ||
abstract class AdminCli_Module_Base | ||
{ | ||
/** | ||
* 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(); | ||
} | ||
|
||
/** | ||
* Indicate if the module provides an option group. | ||
* | ||
* @return boolean True if an option group should be added. | ||
*/ | ||
public function hasOptionGroup() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Return the action arguments supported by this module. | ||
* | ||
* @return array A list of supported action arguments. | ||
*/ | ||
public function getActions() | ||
{ | ||
return array(); | ||
} | ||
|
||
/** | ||
* Return the options that should be explained in the context help. | ||
* | ||
* @return array A list of option help texts. | ||
*/ | ||
public function getContextOptionHelp() | ||
{ | ||
return array(); | ||
} | ||
|
||
/** | ||
* Return the help text for the specified action. | ||
* | ||
* @param string $action The action. | ||
* | ||
* @return string The help text. | ||
*/ | ||
public function getHelp($action) | ||
{ | ||
return ''; | ||
} | ||
} |
Oops, something went wrong.