") { echo "\nUsage:\n $script_name [OPTIONS] [,,..] [-D PROP1=value [-D PROP2]]\n\n"; echo "Available options:\n"; echo " -c specify PHP script to be included (handy for setting props,config options,etc)\n"; echo " -V be super verbose\n"; echo " -q be quite, only system messages\n"; echo " -b batch mode: be super quite, don't even output any system messages\n"; echo " -- pass all options verbatim after this mark\n"; } function _collect_tasks() { global $TASKMAN_TASKS; global $TASKMAN_TASK_ALIASES; global $TASKMAN_FILE_CHANGES; $TASKMAN_TASKS = array(); $TASKMAN_TASK_ALIASES = array(); $cands = _get_task_candidates(); foreach($cands as $name => $args) { if(isset($TASKMAN_TASKS[$name])) throw new \taskman\TaskmanException("Task '$name' is already defined"); if(is_array($args)) { $props = array(); if(sizeof($args) > 2) { $props = $args[1]; $func = $args[2]; } else $func = $args[1]; $task = new \taskman\TaskmanTask($func, $name, $props, $TASKMAN_FILE_CHANGES); } else throw new Exception("Task '$name' is invalid"); $TASKMAN_TASKS[$name] = $task; foreach($task->getAliases() as $alias) { if(isset($TASKMAN_TASKS[$alias]) || isset($TASKMAN_TASK_ALIASES[$alias])) throw new \taskman\TaskmanException("Alias '$alias' is already defined for task '$name'"); $TASKMAN_TASK_ALIASES[$alias] = $task; } } _validate_tasks(); } function _validate_tasks() { global $TASKMAN_TASKS; foreach($TASKMAN_TASKS as $task) { try { $before = $task->getPropOr("before", ""); if($before) \taskman\get_task($before)->addBeforeDep($task); $after = $task->getPropOr("after", ""); if($after) \taskman\get_task($after)->addAfterDep($task); foreach($task->getDeps() as $dep_task) \taskman\get_task($dep_task); } catch(Exception $e) { throw new Exception("Task '{$task->getName()}' validation error: " . $e->getMessage()); } } } function _get_task_candidates() { global $TASKMAN_CLOSURES; $cands = array(); //get tasks defined as closures foreach($TASKMAN_CLOSURES as $name => $args) { $cands[$name] = $args; } ksort($cands); return $cands; } function _resolve_callable_prop($name) { $prop = $GLOBALS['TASKMAN_PROP_' . $name]; if(!($prop instanceof \Closure)) return; $value = $prop(); $GLOBALS['TASKMAN_PROP_' . $name] = $value; } function _isset_task($task) { global $TASKMAN_TASKS; global $TASKMAN_TASK_ALIASES; return isset($TASKMAN_TASKS[$task]) || isset($TASKMAN_TASK_ALIASES[$task]); } function _get_hints($task) { global $TASKMAN_TASKS; global $TASKMAN_TASK_ALIASES; $tasks = array_merge(array_keys($TASKMAN_TASKS), array_keys($TASKMAN_TASK_ALIASES)); $found = array_filter($tasks, function($v) use($task) { return strpos($v, $task) === 0; }); $found = array_merge($found, array_filter($tasks, function($v) use($task) { $pos = strpos($v, $task); return $pos !== false && $pos > 0; })); return $found; } //e.g: run,build,zip function _parse_taskstr($str) { $task_spec = array(); $items = explode(',', $str); foreach($items as $item) { $args = null; $task = $item; if(strpos($item, ' ') !== false) @list($task, $args) = explode(' ', $item, 2); if($args) $task_spec[] = array($task, explode(' ', $args)); else $task_spec[] = $task; } return $task_spec; } function _read_env_vars() { $envs = getenv(); foreach($envs as $k => $v) { if(strpos($k, 'TASKMAN_SET_') === 0) { $prop_name = substr($k, 12); \taskman\log(0, "Setting prop '$prop_name' (with env '$k')\n"); \taskman\set($prop_name, $v); } } } function _process_argv(array &$argv) { global $TASKMAN_LOG_LEVEL; global $TASKMAN_BATCH; global $TASKMAN_NO_DEPS; global $TASKMAN_FILE_CHANGES; $filtered = array(); $process_defs = false; for($i=0;$i