Example #1
0
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 {
                    pantr::writeAction($key, $task->getDescription());