public function run($argc, array $argv) { $options = getopt("c::h::", ["clean:", "help::"]); if (isset($options['h']) || isset($options['help'])) { self::usage(); return; } $cleanOutput = false; if (isset($options['c']) || isset($options['clean'])) { $cleanOutput = true; } $list = []; \Phasty\Tman\TaskManager::getInstance()->scanDir(function ($className) use(&$list, $cleanOutput) { $runTimes = $className::getRunTime(); if (!$runTimes) { return; } $className = \Phasty\Tman\TaskManager::fromClassName(substr($className, strlen($this->cfg["tasksNs"]))); foreach ((array) $runTimes as $args => $runTime) { if (substr(trim($runTime), 0, 1) === '#' && $cleanOutput) { continue; } $list[] = "{$runTime} " . $this->cfg["tman"] . " run " . "{$className}" . (is_string($args) ? " {$args}" : ""); } }); if (!empty($list)) { echo implode(" #tman:" . $this->cfg["tman"] . "\n", $list) . " #tman:" . $this->cfg["tman"] . "\n"; } }
public function run($argc, array $argv) { if (empty($argc)) { self::usage(); return; } $taskClassName = $this->cfg["tasksNs"] . array_shift($argv); $task = \Phasty\Tman\TaskManager::getClassInstance($taskClassName, ["Phasty\\Tman\\Task\\ITask"], $this->cfg); if (!$task) { self::usage(); return; } $options = getopt("v::", ["time-limit::", "verbose::"]); if (!empty($options["time-limit"])) { if (!is_numeric($options["time-limit"])) { self::usage(); return; } set_time_limit($options["time-limit"]); } if (isset($options['v']) || isset($options['verbose'])) { $task->setVerbose(1); } call_user_func_array([$task, "run"], $argv); }
public function run($argc, array $argv) { $options = getopt("p::h::", ["pretend:", "help::"]); if (isset($options['h']) || isset($options['help'])) { self::usage(); return; } $this->showPretends = isset($options['p']) || isset($options['pretend']); $pretend = []; $list = []; \Phasty\Tman\TaskManager::getInstance()->scanDir(function ($className) use(&$pretend, &$list) { $implements = class_implements($className); if (!isset($implements["Phasty\\Tman\\Task\\ITask"])) { if ($this->showPretends) { $pretend[] = \Tman\TaskManager::fromClassName($className); } return; } $runTimes = $className::getRunTime(); $isInCron = 0; foreach ((array) $runTimes as $runTime) { if (substr(trim($runTime), 0, 1) === '#') { continue; } $isInCron++; } $isInCron = $isInCron ? $isInCron == 1 ? "+\t" : "{$isInCron}\t" : " \t"; $list[] = $isInCron . self::padString(substr(\Phasty\Tman\TaskManager::fromClassName($className), strlen($this->cfg["tasksNs"]))) . $className::getDescription(); }); if (!empty($list)) { $c = count($list); echo "{$c} task" . ($c > 1 ? "s are" : " is") . " accessable:\n"; echo "\tCron\t" . self::padString("Task") . "Description\n\t"; echo implode("\n\t", $list), "\n"; } if (!empty($pretend) && $this->showPretends) { $c = count($pretend); echo "{$c} class" . ($c > 1 ? "s" : "") . " pretends to be task" . ($c == 1 ? "" : "s") . ":\n\t", implode("\n\t", $pretend), "\n"; } }