function findTaskfile($dir) { $taksFiles = ['taskfile', 'Taskfile', 'Taskfile.php', 'taskfile.php']; while (true) { foreach ($taksFiles as $taskFile) { $file = $dir . DIRECTORY_SEPARATOR . $taskFile; if (is_readable($file)) { require $file; return $file; } } if ($dir == '/') { abortTaskman("No Taskfile found (looking for: " . implode(', ', $taksFiles) . ")"); } $dir = dirname($dir); } }
if ($taskfile) { if (!is_readable($taskfile)) { abortTaskman("No Taskfile found (looking for: {$taskfile})"); } if (is_file($taskfile)) { require $taskfile; } else { $taskfile = findTaskfile($taskfile); } $cmd = isset($argv[3]) ? $argv[3] : null; $taskArgs = array_slice($argv, 4); } else { $taskfile = findTaskfile(getcwd()); $cmd = isset($argv[1]) ? $argv[1] : null; $taskArgs = array_slice($argv, 2); } echo "(in {$taskfile})\n"; if (isset($opt['T']) || isset($opt['tasks'])) { $tasks = Taskman\Manager::getInstance()->tasks(); ksort($tasks); $max = max(array_map('strlen', array_keys($tasks))); foreach ($tasks as $name => $task) { echo str_pad($name, $max + 4) . $task . "\n"; } exit; } Taskman\Args::init($taskArgs); Taskman\Manager::getInstance()->invoke(empty($cmd) ? 'default' : $cmd, $taskArgs); } catch (Exception $e) { abortTaskman($e->getMessage()); }