public static function push($tgzPath) { $push = new \Pearfarm_Task_Push(); try { $push->run(array('push', $tgzPath)); } catch (\Pearfarm_TaskArgumentException $ex) { pantr::writeln($ex->getMessage(), pantr::ERROR); pantr::log()->error($ex); } }
public function execute(Task $task, $abortOnFailure = true) { $path = $this->executionStrategyFactory->get($task); foreach ($path as $subTaskName) { $subTask = $this->taskRepository->getTask($subTaskName); $status = $subTask($this->args); if ($status == Status::FAILURE && $abortOnFailure) { pantr::writeln('Task "' . $subTaskName . '" failed. Aborting.', pantr::ERROR); return Status::FAILURE; } } return Status::SUCCESS; }
public function run() { // pure args $args = func_get_args(); if (count($args) == 1 && is_array($args[0])) { $args = $args[0]; } // this request $req = self::getRequestContainer($args); $taskName = $req[0]; $useGlobalTasks = isset($req['global']); // load local pantrfile // we only need to load this once // unless the --file option is specified in which case // we load it if (!$useGlobalTasks && ($this->pantrfileLoaded == false || isset($req['file']))) { $this->pantrfileLoaded = true; $pantrfile = $this->pantrfileFactory->getTaskFile($req['file'] ?: 'pantrfile'); if (!is_null($pantrfile)) { // change current dir to pantrfile chdir($pantrfile->getPath()); $pantrfile->load($this->tasks); } else { if ($taskName[0] != ':') { // not a global task pantr::writeln('No pantrfile found.', \pantr\pantr::WARNING); } } } // prepare task $task = $this->getTask($taskName); if (is_null($task)) { throw new NoTaskFoundException($taskName); } $taskArgs = $this->getTaskArgs($taskName, $args); // and now - finally - execute it $executor = $this->taskExecutorFactory->get($taskArgs); $executor->execute($task, $req['ignore-failure'] ?: true); }
/** Instead of manually tracking the beginning and end of a silent * block you can use this method to execute a function silently. * Overloaded method calls: * <code>pantr::silent($action, $msg, $fn)</code> * <code>pantr::silent($msg, $fn)</code> * <code>pantr::silent($fn)</code> * * If $action and $msg (or just $msg) are specified pantr will emit * them as output before switching to silent mode. * It is recommended to do this in order to notify the user of * what is happening. */ public static function silent() { $args = func_get_args(); switch (count($args)) { case 3: pantr::writeAction($args[0], $args[1]); $fn = $args[2]; break; case 2: pantr::writeln($args[0]); $fn = $args[1]; break; case 1: $fn = $args[0]; break; default: throw new \Exception('Invalid method invokation.'); } pantr::beginSilent(); $fn(); pantr::endSilent(); }
public function sync($silent = true) { $pkgs = $this->repo->listAllPackages(); pantr::writeAction('sync', 'PEAR repository'); foreach ($this->channels as $channel => $packages) { // discover channel if it is new if (!isset($pkgs[$channel])) { if ($silent) { pantr::beginSilent('add', 'channel ' . $channel); } $this->repo->discoverChannel($channel); if ($silent) { pantr::endSilent(); } $pkgs[$channel] = array(); } // now check if all packages from this channel are installed foreach ($packages as $pkg => $version) { if (!in_array($pkg, $pkgs[$channel])) { // $channel/$pkg[-$version] if ($silent) { pantr::beginSilent('install', 'package ' . $pkg); } try { $this->repo->install($channel . '/' . $pkg . ($version != '' ? '-' . $version : '')); } catch (\Exception $ex) { pantr::writeln($ex, pantr::WARNING); } if ($silent) { pantr::endSilent(); } $pkgs[$channel][] = $pkg; } } // check if packages are installed that are not specified foreach ($pkgs[$channel] as $pkg) { if (!isset($packages[$pkg])) { if ($silent) { pantr::beginSilent('delete', 'package ' . $pkg); } $this->repo->uninstall($channel . '/' . $pkg); if ($silent) { pantr::endSilent(); } } } } // delete unknown channels foreach ($pkgs as $channel => $packs) { if (!isset($this->channels[$channel])) { pantr::writeln($channel); foreach ($packs as $pkg) { if ($silent) { pantr::beginSilent('delete', 'package ' . $pkg); } $this->repo->uninstall($channel . '/' . $pkg); if ($silent) { pantr::endSilent(); } } if ($silent) { pantr::beginSilent('delete', 'channel ' . $channel); } $this->repo->deleteChannel($channel); if ($silent) { pantr::endSilent(); } } } }
PEAR::registerTasks(); pantr::task('help', 'Display this help message')->usage('help <task>')->option('global-tasks')->shorthand('g')->desc('Show global pantr tasks only')->run(function ($req) { // show info on one task if (isset($req[0])) { $taskName = $req[0]; $tasks = pantr::getDefinedTasks(); if (isset($tasks[$taskName])) { $task = $tasks[$taskName]; if ($task->getName() == 'help') { $task->desc('Display detailed information for a task'); } $task->printHelp(); } } else { // show summary of all tasks pantr::writeln('Usage:', pantr::SECTION)->write('pantr [options]')->write(' <task> ', pantr::PARAMETER)->writeln('[args]'); Application::printOptions(); pantr::out()->nl()->writeln('Available tasks:', pantr::SECTION); $showGlobalTasks = isset($req['global-tasks']); $tasks = pantr::getDefinedTasks(); $names = array_keys($tasks); sort($names); foreach ($names as $key) { $task = $tasks[$key]; $taskName = $task->getName(); $isGlobalTask = $task->isGlobal(); $showTask = $task->isHidden() == false && $showGlobalTasks == $isGlobalTask; if ($showTask) { if ($task->getName() != $key) { pantr::writeAction($key, 'Alias for [' . $task->getName() . '|INFO]'); } else {