diff --git a/.gitignore b/.gitignore index b2a69e9..e7a1f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store vendor +deploy diff --git a/Phakefile b/Phakefile deleted file mode 100644 index 7121b9a..0000000 --- a/Phakefile +++ /dev/null @@ -1,42 +0,0 @@ -get_non_options() as $option) -{ - if(strpos($option, '=') === false) $tasks[] = $option; - else $task_args[] = $option; -} - -// set our top level tasks and lib -$app = phake\Builder::$global->get_application(); -$app->set_args(phake\Utils::parse_args($task_args)); -$app->top_level_tasks = count($tasks)? $tasks : array('default'); -$app->dir = __DIR__.'/lib'; - -// load Pomander/Pomfile -$runfile = \Pomander::resolve_runfile(getcwd()); -if(!$runfile) -{ - $pom = new \Pomander\Builder(); - $pom->run(); -}else -{ - phake\load_runfile($runfile); -} diff --git a/bin/pom b/bin/pom index 6f2e227..a9fe171 100755 --- a/bin/pom +++ b/bin/pom @@ -1,10 +1,24 @@ #!/usr/bin/env php exec($GLOBALS['argv']); exit($status); diff --git a/composer.json b/composer.json index 415bc8d..24508ba 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ } ], "require": { - "jaz303/phake": "*", - "phpseclib/phpseclib": "*" + "jaz303/phake": "@dev", + "phpseclib/phpseclib": "@stable" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index 62d2964..cbade26 100644 --- a/composer.lock +++ b/composer.lock @@ -3,20 +3,20 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "c15580c25e2984edd75b0e55c9096694", + "hash": "4cdf987f1d29ae0931e041c8cdaeea62", "packages": [ { "name": "jaz303/phake", - "version": "v0.5.0", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/jaz303/phake.git", - "reference": "v0.5.0" + "reference": "e78836990de25ad195b1e4564385a588efb75820" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jaz303/phake/zipball/v0.5.0", - "reference": "v0.5.0", + "url": "https://api.github.com/repos/jaz303/phake/zipball/e78836990de25ad195b1e4564385a588efb75820", + "reference": "e78836990de25ad195b1e4564385a588efb75820", "shasum": "" }, "require": { @@ -26,6 +26,15 @@ "bin/phake" ], "type": "library", + "autoload": { + "psr-0": { + "phake": "lib/" + }, + "files": [ + "lib/functions.php", + "lib/term_colors.php" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" @@ -43,7 +52,7 @@ "automation", "cli" ], - "time": "2013-05-27 18:36:49" + "time": "2013-08-21 08:36:46" }, { "name": "phpseclib/phpseclib", @@ -51,12 +60,12 @@ "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "0.3.5" + "reference": "fe3765fe1773c9d62985d05d5b5da24c921c4bd0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/0.3.5", - "reference": "0.3.5", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/fe3765fe1773c9d62985d05d5b5da24c921c4bd0", + "reference": "fe3765fe1773c9d62985d05d5b5da24c921c4bd0", "shasum": "" }, "require": { @@ -127,9 +136,10 @@ ], "minimum-stability": "stable", - "stability-flags": [ - - ], + "stability-flags": { + "jaz303/phake": 20, + "phpseclib/phpseclib": 0 + }, "platform": [ ], diff --git a/lib/Pomander.php b/lib/Pomander.php index f095f51..cbb2d1b 100644 --- a/lib/Pomander.php +++ b/lib/Pomander.php @@ -4,41 +4,15 @@ class Pomander { - public static function resolve_runfile($directory) + public static function version() { - $runfiles = array('Phakefile','Phakefile.php','Pomfile','Pomfile.php'); - do - { - foreach($runfiles as $r) - { - $candidate = $directory.'/'.$r; - if(file_exists($candidate)) return $candidate; - } - if($directory == '/') return false; - $directory = dirname($directory); - } while (true); + return array(0,3,9); } } // set default date if(function_exists('date_default_timezone_set')) date_default_timezone_set('UTC'); -set_error_handler(function($errno,$errstr,$errfile,$errline) { - puts("aborted!"); - puts("$errstr\n"); - if($errno <= 0) $errno = 1; - global $trace; - if($trace) - { - $exception = new \ErrorException($errstr, 0, $errno, $errfile, $errline); - puts($exception->getTraceAsString()); - }else - { - puts("(See full trace by running task with --trace)"); - } - exit($errno); -}); - //utils function info($status,$msg) { @@ -68,9 +42,10 @@ function puts($text) { echo $text.PHP_EOL; } function home() { - if(!isset(builder()->get_application()->home)) - builder()->get_application()->home = trim(shell_exec("cd && pwd"),"\r\n"); - return builder()->get_application()->home; + $app = builder()->get_application(); + if(!isset($app->home)) + $app->home = trim(shell_exec("cd && pwd"),"\r\n"); + return $app->home; } function run() diff --git a/lib/Pomander/Builder.php b/lib/Pomander/Builder.php index 01f7556..7eedff4 100644 --- a/lib/Pomander/Builder.php +++ b/lib/Pomander/Builder.php @@ -51,7 +51,8 @@ public function run($first = true) $app->env->multi_role_support("db",$app); }); - require dirname(__DIR__).'/tasks/default.php'; + $tasks = glob(dirname(__DIR__).'/tasks/*.php'); + foreach($tasks as $task) require $task; if($first) $this->inject_default($app); } diff --git a/lib/Pomander/Cli.php b/lib/Pomander/Cli.php new file mode 100644 index 0000000..aec02a4 --- /dev/null +++ b/lib/Pomander/Cli.php @@ -0,0 +1,161 @@ +get_options() as $option => $value) $this->handle_option($option); + + $task_args = array(); + $tasks = array(); + + // handle tasks and task vars + foreach($parser->get_non_options() as $option) + { + if(strpos($option, '=') === false) $tasks[] = $option; + else $task_args[] = $option; + } + + $this->app = new Application(); + $this->app->set_args(\phake\Utils::parse_args($task_args)); + $this->app->top_level_tasks = count($tasks) ? $tasks : array('default'); + $this->app->dir = dirname(__DIR__); + + \phake\Builder::$global = new \phake\Builder($this->app); + + // load Pomander/Pomfile + $runfile = $this->resolve_runfile(getcwd()); + if(!$runfile) + { + $pom = new \Pomander\Builder(); + $pom->run(); + }else + { + $directory = dirname($runfile); + if(!@chdir($directory)) + throw new \Exception("Couldn't change to directory '$directory'"); + else + echo "(in $directory)\n"; + require $runfile; + } + + if($this->action == "list") + { + $this->list_tasks(); + return 0; + } + + $this->app->reset(); + + switch($this->action) + { + case 'list': + $this->list_tasks(); + break; + case 'invoke': + foreach($tasks as $task_name) $this->app->invoke($task_name); + break; + } + }catch(\phake\TaskNotFoundException $tnfe) + { + $this->fatal($tnfe, "Don't know how to build task '$task_name'\n"); + }catch(\Exception $e) + { + $this->fatal($e, null); + } + } + + public function error_handler($errno, $errstr, $errfile, $errline) + { + $exception = new \ErrorException($errstr, 0, $errno, $errfile, $errline); + return $this->fatal($exception, $errstr, $errno); + } + + public function exception_handler(\Exception $e) + { + return $this->fatal($e); + } + + protected function handle_option($option) + { + switch($option) + { + case "t": + case "trace": + $this->trace = true; + break; + case "T": + case "tasks": + $this->action = "list"; + break; + case "V": + case "version": + echo "Pomander ".implode(".", \Pomander::version())."\n"; + exit; + break; + case "h": + case "H": + case "help": + echo "Usage:\n"; + echo "pom {options} tasks...\n\n"; + echo "Options:\n"; + echo " -T, --tasks Display the available tasks.\n"; + echo " -t, --trace Turn on invoke/execute tracing, enable full backtrace.\n"; + echo " -V, --version Display the program version.\n"; + echo " -h, -H, --help Display the help message.\n"; + exit; + break; + default: + throw new \Exception("Unknown command line option '$option'"); + break; + } + } + + protected function fatal($exception, $message = null, $status = 1) + { + puts("aborted!"); + if(!$message) $message = $exception->getMessage(); + if(!$message) $message = get_class($exception); + puts("$message\n"); + if($this->trace) + puts($exception->getTraceAsString()); + else + puts("(See full trace by running task with --trace)"); + exit($status > 0 ? $status : 1); + } + + protected function list_tasks() + { + $task_list = $this->app->get_task_list(); + if(!count($task_list)) return; + $max = max(array_map('strlen', array_keys($task_list))); + foreach($task_list as $name => $desc) + echo str_pad($name, $max + 4) . $desc . "\n"; + } + + protected function resolve_runfile($directory) + { + $runfiles = array('Phakefile','Phakefile.php','Pomfile','Pomfile.php'); + do + { + foreach($runfiles as $r) + { + $candidate = $directory.'/'.$r; + if(file_exists($candidate)) return $candidate; + } + if($directory == '/') return false; + $directory = dirname($directory); + } while (true); + } +} diff --git a/lib/Pomander/OptionParser.php b/lib/Pomander/OptionParser.php index 99d17e1..48ce8bc 100644 --- a/lib/Pomander/OptionParser.php +++ b/lib/Pomander/OptionParser.php @@ -8,20 +8,24 @@ class OptionParser private $options; private $non_options; - public function __construct($args) { + public function __construct($args) + { $this->args = $args; $this->parse(); } - public function get_options() { + public function get_options() + { return $this->options; } - public function get_non_options() { + public function get_non_options() + { return $this->non_options; } - protected function parse() { + protected function parse() + { $this->options = array(); $this->non_options = array(); $last_opt = null; @@ -53,7 +57,8 @@ protected function parse() { } } - protected function append_option($option) { + protected function append_option($option) + { if (isset($this->options[$option])) { $this->options[$option] = (array) $this->options[$option]; $this->options[$option][] = false; @@ -62,7 +67,8 @@ protected function append_option($option) { } } - protected function set_option_value($option, $value) { + protected function set_option_value($option, $value) + { if (is_array($this->options[$option])) { $len = count($this->options[$option]); $this->options[$option][$len - 1] = $value; @@ -71,7 +77,8 @@ protected function set_option_value($option, $value) { } } - protected function next() { + protected function next() + { if ($this->index == count($this->args)) { return false; }