Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
421d6580dc | |
|
dbf30f1231 | |
|
abe8d938cb | |
|
e68ad37770 | |
|
8dc71ab534 | |
|
d40c2fe201 |
|
@ -4,20 +4,27 @@ use Exception;
|
||||||
|
|
||||||
class TaskmanArtefact
|
class TaskmanArtefact
|
||||||
{
|
{
|
||||||
|
private \taskman\TaskmanTask $task;
|
||||||
private string $path;
|
private string $path;
|
||||||
private array $sources_fn = array();
|
private array $sources_fn = array();
|
||||||
private array $sources_spec = array();
|
private array $sources_spec = array();
|
||||||
private iterable $sources = array();
|
private iterable $sources = array();
|
||||||
private array $sources_changed = array();
|
private array $sources_changed = array();
|
||||||
private array $sources_changed_fn = array();
|
private array $sources_changed_fn = array();
|
||||||
private array $sources_newer = array();
|
private array $sources_affected = array();
|
||||||
|
|
||||||
function __construct(string $path, array $sources_spec)
|
function __construct(\taskman\TaskmanTask $task, string $path, array $sources_spec)
|
||||||
{
|
{
|
||||||
|
$this->task = $task;
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->sources_spec = $sources_spec;
|
$this->sources_spec = $sources_spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTask() : \taskman\TaskmanTask
|
||||||
|
{
|
||||||
|
return $this->task;
|
||||||
|
}
|
||||||
|
|
||||||
function getPath() : string
|
function getPath() : string
|
||||||
{
|
{
|
||||||
return $this->path;
|
return $this->path;
|
||||||
|
@ -36,6 +43,7 @@ class TaskmanArtefact
|
||||||
if(isset($this->sources_fn[$idx]))
|
if(isset($this->sources_fn[$idx]))
|
||||||
{
|
{
|
||||||
$fn = $this->sources_fn[$idx];
|
$fn = $this->sources_fn[$idx];
|
||||||
|
\taskman\log(2, "Task '{$this->task->getName()}' artefact '{$this->path}' resolving sources at $idx\n");
|
||||||
$sources = $fn();
|
$sources = $fn();
|
||||||
$this->sources[$idx] = $sources;
|
$this->sources[$idx] = $sources;
|
||||||
return $sources;
|
return $sources;
|
||||||
|
@ -62,6 +70,7 @@ class TaskmanArtefact
|
||||||
if(isset($this->sources_changed_fn[$idx]))
|
if(isset($this->sources_changed_fn[$idx]))
|
||||||
{
|
{
|
||||||
$fn = $this->sources_changed_fn[$idx];
|
$fn = $this->sources_changed_fn[$idx];
|
||||||
|
\taskman\log(2, "Task '{$this->task->getName()}' artefact '{$this->path}' resolving changed sources at $idx\n");
|
||||||
$changed = $fn();
|
$changed = $fn();
|
||||||
$this->sources_changed[$idx] = $changed;
|
$this->sources_changed[$idx] = $changed;
|
||||||
return $changed;
|
return $changed;
|
||||||
|
@ -70,23 +79,31 @@ class TaskmanArtefact
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//obsolete
|
||||||
function isSourcesNewer(int $idx) : bool
|
function isSourcesNewer(int $idx) : bool
|
||||||
{
|
{
|
||||||
return isset($this->sources_newer[$idx]) && $this->sources_newer[$idx];
|
return $this->isSourcesAffected($idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewerSourcesIndices() : array
|
function isSourcesAffected(int $idx) : bool
|
||||||
{
|
{
|
||||||
return array_keys($this->sources_newer);
|
return isset($this->sources_affected[$idx]) && $this->sources_affected[$idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAffectedSourcesIndices() : array
|
||||||
|
{
|
||||||
|
return array_keys($this->sources_affected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStale() : bool
|
function isStale() : bool
|
||||||
{
|
{
|
||||||
return count($this->sources_newer) > 0;
|
return count($this->sources_affected) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSources(?\taskman\TaskmanFileChanges $file_changes)
|
function initSources()
|
||||||
{
|
{
|
||||||
|
$file_changes = $this->task->getFileChanges();
|
||||||
|
|
||||||
$all_src_specs = $this->getSourcesSpec();
|
$all_src_specs = $this->getSourcesSpec();
|
||||||
//let's process a convenience special case
|
//let's process a convenience special case
|
||||||
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]))
|
if(count($all_src_specs) > 0 && !is_array($all_src_specs[0]))
|
||||||
|
@ -111,7 +128,7 @@ class TaskmanArtefact
|
||||||
$changed = array();
|
$changed = array();
|
||||||
foreach($src_spec[0] as $spec_dir)
|
foreach($src_spec[0] as $spec_dir)
|
||||||
{
|
{
|
||||||
$matches = $file_changes->matchDirectory($spec_dir);
|
$matches = $file_changes->matchDirectory($spec_dir, $src_spec[1]);
|
||||||
$changed[$spec_dir] = $matches;
|
$changed[$spec_dir] = $matches;
|
||||||
}
|
}
|
||||||
return new TaskmanDirFiles($changed);
|
return new TaskmanDirFiles($changed);
|
||||||
|
@ -134,14 +151,16 @@ class TaskmanArtefact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkNewerSources(?\taskman\TaskmanFileChanges $file_changes) : bool
|
function checkAffectedSources() : bool
|
||||||
{
|
{
|
||||||
|
$file_changes = $this->task->getFileChanges();
|
||||||
|
|
||||||
foreach($this->getSourcesSpec() as $src_idx => $src_spec)
|
foreach($this->getSourcesSpec() as $src_idx => $src_spec)
|
||||||
{
|
{
|
||||||
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
|
$sources = $file_changes != null ? $this->getChangedSources($src_idx) : $this->getSources($src_idx);
|
||||||
if(is_stale($this->getPath(), $sources))
|
if(is_stale($this->getPath(), $sources))
|
||||||
{
|
{
|
||||||
$this->sources_newer[$src_idx] = true;
|
$this->sources_affected[$src_idx] = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,6 +181,11 @@ class TaskmanDirFiles implements \ArrayAccess, \Countable, \Iterator
|
||||||
$this->dir2files[$dir] = $files;
|
$this->dir2files[$dir] = $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __toString() : string
|
||||||
|
{
|
||||||
|
return var_export($this->dir2files, true);
|
||||||
|
}
|
||||||
|
|
||||||
function toMap() : array
|
function toMap() : array
|
||||||
{
|
{
|
||||||
return $this->dir2files;
|
return $this->dir2files;
|
||||||
|
|
|
@ -166,7 +166,7 @@ function _read_env_vars()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _process_argv(&$argv)
|
function _process_argv(array &$argv)
|
||||||
{
|
{
|
||||||
global $TASKMAN_LOG_LEVEL;
|
global $TASKMAN_LOG_LEVEL;
|
||||||
global $TASKMAN_BATCH;
|
global $TASKMAN_BATCH;
|
||||||
|
@ -202,6 +202,14 @@ function _process_argv(&$argv)
|
||||||
{
|
{
|
||||||
$TASKMAN_LOG_LEVEL = -1;
|
$TASKMAN_LOG_LEVEL = -1;
|
||||||
}
|
}
|
||||||
|
else if($v == '-l')
|
||||||
|
{
|
||||||
|
if(!isset($argv[$i+1]))
|
||||||
|
throw new \taskman\TaskmanException("Log level is missing");
|
||||||
|
|
||||||
|
$TASKMAN_LOG_LEVEL = intval($argv[$i+1]);
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
else if($v == '-O')
|
else if($v == '-O')
|
||||||
{
|
{
|
||||||
$TASKMAN_NO_DEPS = true;
|
$TASKMAN_NO_DEPS = true;
|
||||||
|
@ -253,3 +261,32 @@ function _process_argv(&$argv)
|
||||||
$argv = $filtered;
|
$argv = $filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _extract_lines_from_file(string $file_path) : array
|
||||||
|
{
|
||||||
|
$lines = array();
|
||||||
|
|
||||||
|
$fh = fopen($file_path, 'r+');
|
||||||
|
|
||||||
|
if($fh === false)
|
||||||
|
return $lines;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(flock($fh, LOCK_EX))
|
||||||
|
{
|
||||||
|
while(($line = fgets($fh)) !== false)
|
||||||
|
$lines[] = $line;
|
||||||
|
|
||||||
|
ftruncate($fh, 0);
|
||||||
|
|
||||||
|
flock($fh, LOCK_UN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
fclose($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
197
taskman.inc.php
197
taskman.inc.php
|
@ -2,11 +2,6 @@
|
||||||
namespace taskman;
|
namespace taskman;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
include_once(__DIR__ . '/internal.inc.php');
|
|
||||||
include_once(__DIR__ . '/util.inc.php');
|
|
||||||
include_once(__DIR__ . '/tasks.inc.php');
|
|
||||||
include_once(__DIR__ . '/artefact.inc.php');
|
|
||||||
|
|
||||||
$GLOBALS['TASKMAN_TASKS'] = array();
|
$GLOBALS['TASKMAN_TASKS'] = array();
|
||||||
$GLOBALS['TASKMAN_CLOSURES'] = array();
|
$GLOBALS['TASKMAN_CLOSURES'] = array();
|
||||||
$GLOBALS['TASKMAN_STACK'] = array();
|
$GLOBALS['TASKMAN_STACK'] = array();
|
||||||
|
@ -21,6 +16,11 @@ $GLOBALS['TASKMAN_ERROR_HANDLER'] = null;
|
||||||
$GLOBALS['TASKMAN_START_TIME'] = 0;
|
$GLOBALS['TASKMAN_START_TIME'] = 0;
|
||||||
$GLOBALS['TASKMAN_FILES_CHANGES'] = null;
|
$GLOBALS['TASKMAN_FILES_CHANGES'] = null;
|
||||||
|
|
||||||
|
include_once(__DIR__ . '/internal.inc.php');
|
||||||
|
include_once(__DIR__ . '/util.inc.php');
|
||||||
|
include_once(__DIR__ . '/tasks.inc.php');
|
||||||
|
include_once(__DIR__ . '/artefact.inc.php');
|
||||||
|
|
||||||
class TaskmanException extends Exception
|
class TaskmanException extends Exception
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class TaskmanTask
|
||||||
if(is_array($specs))
|
if(is_array($specs))
|
||||||
{
|
{
|
||||||
foreach($specs as $dst => $src_spec)
|
foreach($specs as $dst => $src_spec)
|
||||||
$artefacts[] = new artefact\TaskmanArtefact($dst, $src_spec);
|
$artefacts[] = new artefact\TaskmanArtefact($this, $dst, $src_spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $artefacts;
|
return $artefacts;
|
||||||
|
@ -181,7 +181,7 @@ class TaskmanTask
|
||||||
|
|
||||||
$level = count($TASKMAN_STACK)-1;
|
$level = count($TASKMAN_STACK)-1;
|
||||||
|
|
||||||
msg_sys("***** ".str_repeat('-', $level)."task '" . $this->getName() . "' start *****\n");
|
log(0, "***** ".str_repeat('-', $level)."task '" . $this->getName() . "' start *****\n");
|
||||||
|
|
||||||
if(!$TASKMAN_NO_DEPS)
|
if(!$TASKMAN_NO_DEPS)
|
||||||
{
|
{
|
||||||
|
@ -199,7 +199,7 @@ class TaskmanTask
|
||||||
if(!$TASKMAN_NO_DEPS)
|
if(!$TASKMAN_NO_DEPS)
|
||||||
run_many($this->after_deps);
|
run_many($this->after_deps);
|
||||||
|
|
||||||
msg_sys("***** ".str_repeat('-', $level)."task '" . $this->getName() . "' done(" .
|
log(0, "***** ".str_repeat('-', $level)."task '" . $this->getName() . "' done(" .
|
||||||
round(microtime(true)-$bench,2) . '/' .round(microtime(true)-$TASKMAN_START_TIME,2) . " sec.) *****\n");
|
round(microtime(true)-$bench,2) . '/' .round(microtime(true)-$TASKMAN_START_TIME,2) . " sec.) *****\n");
|
||||||
|
|
||||||
$this->has_run[$args_str] = true;
|
$this->has_run[$args_str] = true;
|
||||||
|
@ -266,20 +266,18 @@ class TaskmanTask
|
||||||
|
|
||||||
private function _checkIfArtefactsStale() : bool
|
private function _checkIfArtefactsStale() : bool
|
||||||
{
|
{
|
||||||
$file_changes = $this->getFileChanges();
|
|
||||||
|
|
||||||
$stale_found = false;
|
$stale_found = false;
|
||||||
|
|
||||||
foreach($this->getArtefacts() as $artefact)
|
foreach($this->getArtefacts() as $artefact)
|
||||||
{
|
{
|
||||||
$artefact->initSources($file_changes);
|
$artefact->initSources();
|
||||||
|
|
||||||
if(!$stale_found && $artefact->checkNewerSources($file_changes))
|
if(!$stale_found && $artefact->checkAffectedSources())
|
||||||
$stale_found = true;
|
$stale_found = true;
|
||||||
|
|
||||||
if($artefact->isStale())
|
if($artefact->isStale())
|
||||||
{
|
{
|
||||||
msg_sys("Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getNewerSourcesIndices()).") is stale\n");
|
log(0, "Task '{$this->name}' artefact '{$artefact->getPath()}' (sources at ".implode(',', $artefact->getAffectedSourcesIndices()).") is stale\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,28 +297,37 @@ class TaskmanTask
|
||||||
|
|
||||||
class TaskmanFileChanges
|
class TaskmanFileChanges
|
||||||
{
|
{
|
||||||
|
const Changed = 1;
|
||||||
|
const Created = 2;
|
||||||
|
const Renamed = 3;
|
||||||
|
const Deleted = 4;
|
||||||
|
|
||||||
|
//file => status
|
||||||
private $changed = array();
|
private $changed = array();
|
||||||
private $removed = array();
|
|
||||||
|
|
||||||
static function parse(string $json_or_file)
|
static function parse(string $json_or_file)
|
||||||
{
|
{
|
||||||
if($json_or_file[0] == '[')
|
if($json_or_file[0] == '[')
|
||||||
$json = $json_or_file;
|
$json = $json_or_file;
|
||||||
else
|
else
|
||||||
$json = file_get_contents($json_or_file);
|
{
|
||||||
|
$lines = internal\_extract_lines_from_file($json_or_file);
|
||||||
|
$json = '[' . implode(',', $lines) . ']';
|
||||||
|
}
|
||||||
|
|
||||||
$decoded = json_decode($json, true);
|
$decoded = json_decode($json, true);
|
||||||
if(!is_array($decoded))
|
if(!is_array($decoded))
|
||||||
throw new Exception('Bad json');
|
throw new Exception('Bad json: ' . $json);
|
||||||
|
|
||||||
$changed = array();
|
$changed = array();
|
||||||
$removed = array();
|
|
||||||
|
|
||||||
$base_dir = dirname($_SERVER['PHP_SELF']);
|
$base_dir = dirname($_SERVER['PHP_SELF']);
|
||||||
|
//for debug
|
||||||
|
//var_dump($decoded);
|
||||||
|
|
||||||
foreach($decoded as $items)
|
foreach($decoded as $items)
|
||||||
{
|
{
|
||||||
if(count($items) != 2)
|
if(count($items) < 2)
|
||||||
throw new Exception('Bad entry');
|
throw new Exception('Bad entry');
|
||||||
list($status, $file) = $items;
|
list($status, $file) = $items;
|
||||||
|
|
||||||
|
@ -337,30 +344,62 @@ class TaskmanFileChanges
|
||||||
|
|
||||||
$file = artefact\normalize_path($file);
|
$file = artefact\normalize_path($file);
|
||||||
|
|
||||||
if($status == 'C')
|
if($status == 'Changed')
|
||||||
$changed[$file] = true;
|
$changed[$file] = self::Changed;
|
||||||
else if($status == 'R')
|
else if($status == 'Created')
|
||||||
$removed[$file] = true;
|
{
|
||||||
|
//let's status for files which were modified and then created
|
||||||
|
if(isset($changed[$file]) && $changed[$file] !== self::Changed)
|
||||||
|
$changed[$file] = self::Created;
|
||||||
|
}
|
||||||
|
else if($status == 'Renamed')
|
||||||
|
$changed[$file] = self::Renamed;
|
||||||
|
else if($status == 'Deleted')
|
||||||
|
$changed[$file] = self::Deleted;
|
||||||
else
|
else
|
||||||
throw new Exception('Unknown status: ' . $status);
|
throw new Exception('Unknown status: ' . $status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TaskmanFileChanges($changed, $removed);
|
return new TaskmanFileChanges($changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
//NOTE: these are actually maps: file => true
|
//NOTE: maps: file => status
|
||||||
function __construct(array $changed, array $removed)
|
function __construct(array $changed)
|
||||||
{
|
{
|
||||||
$this->changed = $changed;
|
$this->changed = $changed;
|
||||||
$this->removed = $removed;
|
}
|
||||||
|
|
||||||
|
function getStatus(string $file) : ?int
|
||||||
|
{
|
||||||
|
return isset($this->changed[$file]) ? $this->changed[$file] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isChanged(string $file) : bool
|
||||||
|
{
|
||||||
|
return $this->getStatus($file) == self::Changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCreated(string $file) : bool
|
||||||
|
{
|
||||||
|
return $this->getStatus($file) == self::Created;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDeleted(string $file) : bool
|
||||||
|
{
|
||||||
|
return $this->getStatus($file) == self::Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRenamed(string $file) : bool
|
||||||
|
{
|
||||||
|
return $this->getStatus($file) == self::Renamed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEmpty() : bool
|
function isEmpty() : bool
|
||||||
{
|
{
|
||||||
return count($this->changed) == 0 && count($this->removed) == 0;
|
return count($this->changed) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchDirectory(string $dir) : array
|
function matchDirectory(string $dir, array $extensions = array()) : array
|
||||||
{
|
{
|
||||||
$dir = rtrim($dir, '/\\');
|
$dir = rtrim($dir, '/\\');
|
||||||
$dir .= DIRECTORY_SEPARATOR;
|
$dir .= DIRECTORY_SEPARATOR;
|
||||||
|
@ -368,25 +407,115 @@ class TaskmanFileChanges
|
||||||
$filtered = [];
|
$filtered = [];
|
||||||
|
|
||||||
foreach($this->changed as $path => $_)
|
foreach($this->changed as $path => $_)
|
||||||
if(strpos($path, $dir) === 0)
|
if(self::matchDirAndExtension($path, $dir, $extensions))
|
||||||
$filtered[] = $path;
|
|
||||||
|
|
||||||
foreach($this->removed as $path => $_)
|
|
||||||
if(strpos($path, $dir) === 0)
|
|
||||||
$filtered[] = $path;
|
$filtered[] = $path;
|
||||||
|
|
||||||
return $filtered;
|
return $filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function matchDirAndExtension(string $path, string $dir, array $extensions) : bool
|
||||||
|
{
|
||||||
|
if(strpos($path, $dir) !== 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach($extensions as $ext)
|
||||||
|
if(!str_ends_with($path, $ext))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function matchFiles(iterable $files) : array
|
function matchFiles(iterable $files) : array
|
||||||
{
|
{
|
||||||
$filtered = [];
|
$filtered = [];
|
||||||
foreach($files as $file)
|
foreach($files as $file)
|
||||||
{
|
{
|
||||||
if(isset($this->changed[$file]) || isset($this->removed[$file]))
|
if(isset($this->changed[$file]))
|
||||||
$filtered[] = $file;
|
$filtered[] = $file;
|
||||||
}
|
}
|
||||||
return $filtered;
|
return $filtered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function main(
|
||||||
|
array $argv = array(),
|
||||||
|
callable $help_func = null,
|
||||||
|
bool $proc_argv = true,
|
||||||
|
bool $read_env_vars = true
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$GLOBALS['TASKMAN_START_TIME'] = microtime(true);
|
||||||
|
|
||||||
|
if($help_func)
|
||||||
|
$GLOBALS['TASKMAN_HELP_FUNC'] = $help_func;
|
||||||
|
|
||||||
|
if($read_env_vars)
|
||||||
|
internal\_read_env_vars();
|
||||||
|
|
||||||
|
if($proc_argv)
|
||||||
|
internal\_process_argv($argv);
|
||||||
|
|
||||||
|
$GLOBALS['TASKMAN_SCRIPT'] = array_shift($argv);
|
||||||
|
|
||||||
|
internal\_collect_tasks();
|
||||||
|
|
||||||
|
$always_tasks = array();
|
||||||
|
$default_task = null;
|
||||||
|
foreach(get_tasks() as $task_obj)
|
||||||
|
{
|
||||||
|
if($task_obj->hasProp('always'))
|
||||||
|
array_unshift($always_tasks, $task_obj);
|
||||||
|
if($task_obj->hasProp('default'))
|
||||||
|
{
|
||||||
|
if($default_task)
|
||||||
|
throw new TaskmanException("Assigned default task '" . $default_task->getName() . "' conflicts with '" . $task_obj->getName() . "'");
|
||||||
|
else
|
||||||
|
$default_task = $task_obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($always_tasks as $always_task)
|
||||||
|
run($always_task);
|
||||||
|
|
||||||
|
if(sizeof($argv) > 0)
|
||||||
|
{
|
||||||
|
$task_str = array_shift($argv);
|
||||||
|
$tasks = internal\_parse_taskstr($task_str);
|
||||||
|
|
||||||
|
if(count($tasks) == 1 && !internal\_isset_task($tasks[0]))
|
||||||
|
{
|
||||||
|
$pattern = $tasks[0];
|
||||||
|
if($pattern[0] == '~')
|
||||||
|
{
|
||||||
|
$pattern = substr($pattern, 1, strlen($pattern) - 1);
|
||||||
|
$is_similar = true;
|
||||||
|
}
|
||||||
|
elseif(substr($pattern, -1, 1) == '~')
|
||||||
|
{
|
||||||
|
$pattern = substr($pattern, 0, strlen($pattern) - 1);
|
||||||
|
$is_similar = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$is_similar = false;
|
||||||
|
$hints = internal\_get_hints($pattern);
|
||||||
|
|
||||||
|
if($is_similar && count($hints) == 1)
|
||||||
|
$tasks = $hints;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$similars = '';
|
||||||
|
if($hints)
|
||||||
|
$similars .= "\nSimilar tasks: " . implode(', ', $hints) . ".";
|
||||||
|
|
||||||
|
throw new Exception("Task '{$tasks[0]}' not found. $similars");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run_many($tasks, $argv);
|
||||||
|
}
|
||||||
|
else if($default_task)
|
||||||
|
run($default_task, $argv);
|
||||||
|
|
||||||
|
log(0, "***** All done (".round(microtime(true)-$GLOBALS['TASKMAN_START_TIME'],2)." sec.) *****\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ task('help', function($args = array())
|
||||||
$all = get_tasks();
|
$all = get_tasks();
|
||||||
foreach($all as $task)
|
foreach($all as $task)
|
||||||
{
|
{
|
||||||
if($filter && (strpos($task->getName(), $filter) === false && strpos($task->getPropOr("alias", ""), $filter) === false))
|
if($filter && (strpos($task->getName(), $filter) === false &&
|
||||||
|
strpos($task->getPropOr("alias", ""), $filter) === false))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(strlen($task->getName()) > $maxlen)
|
if(strlen($task->getName()) > $maxlen)
|
||||||
|
|
80
util.inc.php
80
util.inc.php
|
@ -163,86 +163,6 @@ function _(string $str) : string
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function main($argv = array(), $help_func = null, $proc_argv = true, $read_env_vars = true)
|
|
||||||
{
|
|
||||||
$GLOBALS['TASKMAN_START_TIME'] = microtime(true);
|
|
||||||
|
|
||||||
if($help_func)
|
|
||||||
$GLOBALS['TASKMAN_HELP_FUNC'] = $help_func;
|
|
||||||
|
|
||||||
if($read_env_vars)
|
|
||||||
internal\_read_env_vars();
|
|
||||||
|
|
||||||
if($proc_argv)
|
|
||||||
internal\_process_argv($argv);
|
|
||||||
|
|
||||||
$GLOBALS['TASKMAN_SCRIPT'] = array_shift($argv);
|
|
||||||
|
|
||||||
internal\_collect_tasks();
|
|
||||||
|
|
||||||
$always_tasks = array();
|
|
||||||
$default_task = null;
|
|
||||||
foreach(get_tasks() as $task_obj)
|
|
||||||
{
|
|
||||||
if($task_obj->hasProp('always'))
|
|
||||||
array_unshift($always_tasks, $task_obj);
|
|
||||||
if($task_obj->hasProp('default'))
|
|
||||||
{
|
|
||||||
if($default_task)
|
|
||||||
throw new TaskmanException("Assigned default task '" . $default_task->getName() . "' conflicts with '" . $task_obj->getName() . "'");
|
|
||||||
else
|
|
||||||
$default_task = $task_obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($always_tasks as $always_task)
|
|
||||||
run($always_task);
|
|
||||||
|
|
||||||
if(sizeof($argv) > 0)
|
|
||||||
{
|
|
||||||
$task_str = array_shift($argv);
|
|
||||||
$tasks = internal\_parse_taskstr($task_str);
|
|
||||||
|
|
||||||
if(count($tasks) == 1 && !internal\_isset_task($tasks[0]))
|
|
||||||
{
|
|
||||||
$pattern = $tasks[0];
|
|
||||||
if($pattern[0] == '~')
|
|
||||||
{
|
|
||||||
$pattern = substr($pattern, 1, strlen($pattern) - 1);
|
|
||||||
$is_similar = true;
|
|
||||||
}
|
|
||||||
elseif(substr($pattern, -1, 1) == '~')
|
|
||||||
{
|
|
||||||
$pattern = substr($pattern, 0, strlen($pattern) - 1);
|
|
||||||
$is_similar = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$is_similar = false;
|
|
||||||
$hints = internal\_get_hints($pattern);
|
|
||||||
|
|
||||||
if($is_similar && count($hints) == 1)
|
|
||||||
$tasks = $hints;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("ERROR! Task %s not found\n", $tasks[0]);
|
|
||||||
if($hints)
|
|
||||||
{
|
|
||||||
printf("Similar tasks:\n");
|
|
||||||
foreach($hints as $hint)
|
|
||||||
printf(" %s\n", $hint);
|
|
||||||
}
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run_many($tasks, $argv);
|
|
||||||
}
|
|
||||||
else if($default_task)
|
|
||||||
run($default_task, $argv);
|
|
||||||
|
|
||||||
msg_sys("***** All done (".round(microtime(true)-$GLOBALS['TASKMAN_START_TIME'],2)." sec.) *****\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
function usage($script_name = "<taskman-script>")
|
function usage($script_name = "<taskman-script>")
|
||||||
{
|
{
|
||||||
internal\_default_usage($script_name);
|
internal\_default_usage($script_name);
|
||||||
|
|
Loading…
Reference in New Issue