private function abbrev($options) { $abbrevs = array(); $table = array(); foreach ($options as $option) { $option = pakeTask::get_mini_task_name($option); for ($len = strlen($option) - 1; $len > 0; --$len) { $abbrev = substr($option, 0, $len); if (!array_key_exists($abbrev, $table)) { $table[$abbrev] = 1; } else { ++$table[$abbrev]; } $seen = $table[$abbrev]; if ($seen == 1) { // we're the first word so far to have this abbreviation. $abbrevs[$abbrev] = array($option); } else { if ($seen == 2) { // we're the second word to have this abbreviation, so we can't use it. //unset($abbrevs[$abbrev]); $abbrevs[$abbrev][] = $option; } else { // we're the third word to have this abbreviation, so skip to the next word. continue; } } } } // Non-abbreviations always get entered, even if they aren't unique foreach ($options as $option) { $abbrevs[$option] = array($option); } return $abbrevs; }
public function display_prerequisites() { foreach (pakeTask::get_tasks() as $name => $task) { echo self::$EXEC_NAME . " " . pakeTask::get_mini_task_name($name) . "\n"; foreach ($task->get_prerequisites() as $prerequisite) { echo " {$prerequisite}\n"; } } }
/** * show documentation; use "pake help taskname" to see detailed documentation on task * * @param string $task * @param string $args * @return bool * @author Alexey Zakhlestin */ public static function run_help($task, $args) { if (count($args) == 0) { self::get_instance()->help(); return; } $victim_name = $args[0]; foreach (pakeTask::get_tasks() as $name => $task) { if ($victim_name == $name or $victim_name == pakeTask::get_mini_task_name($name)) { $victim = $task; break; } } $title = 'Documentation for "' . $victim_name . '" task'; pake_echo($title); pake_echo(str_repeat('=', mb_strlen($title))); pake_echo($victim->get_comment() . "\n"); pake_echo($victim->get_help()); }
/** * show documentation; use "pake help taskname" to see detailed documentation on task * * @param string $task * @param string $args * @throws pakeException * @author Alexey Zakhlestin */ public static function run_help($task, $args) { if (count($args) == 0) { self::get_instance()->help(); return; } $victim_name = $args[0]; $task_name = pakeTask::taskname_from_abbreviation($victim_name); $victim = null; foreach (pakeTask::get_tasks() as $name => $task) { if ($task_name == $name or $task_name == pakeTask::get_mini_task_name($name)) { $victim = $task; break; } } if (null === $victim) { throw new pakeException("Couldn't find documentation for {$task_name}"); } $title = 'Documentation for "' . $task_name . '" task'; pake_echo($title); pake_echo(str_repeat('=', mb_strlen($title))); pake_echo($victim->get_comment() . "\n"); pake_echo($victim->get_help()); }
public static function abbrev(array $options) { $abbrevs = array(); $table = array(); foreach ($options as $option) { $option = pakeTask::get_mini_task_name($option); for ($len = strlen($option) - 1; $len > 0; --$len) { $abbrev = substr($option, 0, $len); if (!array_key_exists($abbrev, $table)) { $table[$abbrev] = 1; } else { ++$table[$abbrev]; } $seen = $table[$abbrev]; if ($seen == 1) { $abbrevs[$abbrev] = array($option); } elseif ($seen == 2) { $abbrevs[$abbrev][] = $option; } else { continue; } } } foreach ($options as $option) { $abbrevs[$option] = array($option); } return $abbrevs; }