/bin/hudson-cli.php
PHP | 106 lines | 71 code | 1 blank | 34 comment | 16 complexity | 4eac26acf4cc51af16a18e216b184044 MD5 | raw file
- #!/usr/bin/env php
- <?php
- /**
- * Php4Hudson
- *
- * @version $Id$
- * @author Ladislav Prskavec <ladislav.prskavec@gmail.com>
- * @package php4hudson
- * @category php4hudson
- * @copyright Copyright (c) 2009, Ladislav Prskavec (http://ladislav.prskavec.net)
- * @license MIT http://www.opensource.org/licenses/mit-license.php
- * @link http://code.google.com/p/php4hudson/
- * @filesource
- */
- error_reporting(E_ALL|E_STRICT);
- ini_set('display_errors',true);
- date_default_timezone_set('Europe/Prague');
- /**
- * Zend GetOpt
- */
- require_once('Zend/Console/Getopt.php');
- require_once('Zend/Console/Getopt/Exception.php');
- /**
- * Command line client for php4hudson
- */
- require_once ("../Php4Hudson/phphudson.php");
- require_once ("../Php4Hudson/phphudsonui.php");
- /**
- * Try processing Zend_Console_Getopt
- */
- try {
- $opts = new Zend_Console_Getopt(
- array(
- 'help' => 'Displays usage information.',
- 'version|v' => 'Version',
- 'username|u=s'=> 'Username',
- 'password|p=s'=> 'password',
- 'host|h=s' => 'Hudson URL',
- 'restart|r' => 'restart Hudson',
- 'output|o=s'=> 'output path',
- 'configs|c' => 'get Hudson Configs',
- 'jobs|j' => 'print jobs list',
- 'debug|d' => 'debug'
- )
- );
- $opts->parse();
- } catch (Zend_Console_Getopt_Exception $e) {
- exit($e->getMessage() ."\n\n". $e->getUsageMessage());
- }
- // start processing ops
- // help + without arguments
- if (count($opts->toArray())==0 || isset($opts->help)) {
- php4hudsonUI::printVersion();
- echo $opts->getUsageMessage();
- exit;
- }
- // version
- if (isset($opts->v)) {
- php4hudsonUI::printVersion();
- echo $opts->getUsageMessage();
- }
- // username
- if (isset($opts->u)) {
- $username = $opts->u;
- } else {
- $username = null;
- }
- // passwod
- if (isset($opts->p)) {
- $password = $opts->p;
- } else {
- $password = null;
- }
- // host
- if (isset($opts->h)) {
- $host = $opts->h;
- } else {
- print "Error url to Hudson must be set!\n";
- exit;
- }
- // debug
- if (isset($opts->d)) {
- $debug = true;
- } else {
- $debug = false;
- }
- // output
- if (isset($opts->o)) {
- $output = $opts->o;
- } else {
- $output = null;
- }
- // jobs
- if (isset($opts->j)) {
- php4hudsonUI::printListJobs($host, $username, $password, $debug);
- }
- // config
- if (isset($opts->c)) {
- php4hudsonUI::getConfigs($host, $username, $password, $debug, $output);
- }
- // restart
- if (isset ($opts->r)) {
- php4hudsonUI::system($host, $username, $password, $debug, "restart");
- }
- // end processing ops