Skip to content
Browse files

Add the ability to pass phake a custom Phakefile.

  • Loading branch information...
1 parent 605e0a3 commit b1e7f486a645109a7cbf0191e007e72dfc98e4f0 @trq trq committed Oct 24, 2012
Showing with 27 additions and 18 deletions.
  1. +23 −16 bin/phake
  2. +4 −2 lib/utils.php
View
39 bin/phake
@@ -9,18 +9,20 @@ require dirname(__FILE__) . '/../lib/builder.php';
phake\Builder::$global = new phake\Builder;
try {
-
+
//
// Defaults
-
+
$action = 'invoke';
$task_names = array('default');
$trace = false;
-
+ $runfile = false;
+
$args = $GLOBALS['argv'];
array_shift($args);
$parser = new phake\OptionParser($args);
foreach ($parser->get_options() as $option => $value) {
+ echo "$option => $value\n";
switch ($option) {
case 't':
case 'trace':
@@ -30,11 +32,15 @@ try {
case 'tasks':
$action = 'list';
break;
+ case 'f':
+ case 'file':
+ $runfile = $value;
+ break;
default:
throw new Exception("Unknown command line option '$option'");
}
}
-
+
$cli_args = array();
$cli_task_names = array();
foreach ($parser->get_non_options() as $option) {
@@ -44,34 +50,35 @@ try {
$cli_task_names[] = $option;
}
}
-
+
$cli_args = phake\Utils::parse_args($cli_args);
-
+
if (count($cli_task_names)) {
$task_names = $cli_task_names;
}
-
+
//
// Locate runfile
-
- $runfile = phake\resolve_runfile(getcwd());
- $directory = dirname($runfile);
+ if (!$runfile) {
+ $runfile = phake\resolve_runfile(getcwd());
+ $directory = dirname($runfile);
- if (!@chdir($directory)) {
- throw new Exception("Couldn't change to directory '$directory'");
- } else {
- echo "(in $directory)\n";
+ if (!@chdir($directory)) {
+ throw new Exception("Couldn't change to directory '$directory'");
+ } else {
+ echo "(in $directory)\n";
+ }
}
phake\load_runfile($runfile);
//
// Go, go, go
-
+
$application = phake\Builder::$global->get_application();
$application->set_args($cli_args);
$application->reset();
-
+
switch ($action) {
case 'list':
$task_list = $application->get_task_list();
View
6 lib/utils.php
@@ -18,7 +18,9 @@ function resolve_runfile($directory) {
}
function load_runfile($file) {
- require $file;
+ if (file_exists($file)) {
+ require $file;
+ }
}
function fatal($exception, $message = null) {
@@ -34,4 +36,4 @@ function fatal($exception, $message = null) {
}
die(1);
}
-?>
+?>

0 comments on commit b1e7f48

Please sign in to comment.
Something went wrong with that request. Please try again.