-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show step annotations for manual triggers
annotate `--show` and `--show-pipelines` steps by `*M` for any step with a manual trigger (`trigger: manual`). streamline display of unnamed steps as `no-name` to prevent hiding steps with `--show-pipelines`. for that: extract file-info modules. the file-shower should concentrate on traversing and arranging the information in tables, not so much about data-point string acquisition and formatting. let file-info do that.
- Loading branch information
Showing
8 changed files
with
330 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/* this file is part of pipelines */ | ||
|
||
namespace Ktomk\Pipelines\File\Info; | ||
|
||
use Ktomk\Pipelines\File\File; | ||
use Ktomk\Pipelines\File\Pipeline\Step; | ||
|
||
/** | ||
* info about a step (for show output) | ||
*/ | ||
final class StepInfo | ||
{ | ||
const NO_NAME = 'no-name'; | ||
const CHAR_MANUAL = 'M'; | ||
|
||
/** | ||
* @var Step | ||
*/ | ||
private $step; | ||
private $index; | ||
|
||
/** | ||
* @param Step $step | ||
* @param int $index (zero-based) | ||
*/ | ||
public function __construct(Step $step, $index) | ||
{ | ||
$this->step = $step; | ||
$this->index = (int)$index; | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @param string $separator [optional] | ||
* | ||
* @return string | ||
*/ | ||
public function annotate($string, $separator = ' *') | ||
{ | ||
$buffer = (string)$string; | ||
$annotations = $this->getAnnotations(); | ||
if ($annotations) { | ||
$buffer .= $separator . implode('', $annotations); | ||
} | ||
|
||
return $buffer; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAnnotations() | ||
{ | ||
$annotations = array(); | ||
|
||
$this->step->isManual() && $annotations[] = self::CHAR_MANUAL; | ||
|
||
return $annotations; | ||
} | ||
|
||
/** | ||
* @return \Ktomk\Pipelines\File\Image | ||
*/ | ||
public function getImage() | ||
{ | ||
return $this->step->getImage(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getImageName() | ||
{ | ||
return $this->step->getImage()->getName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
$name = $this->step->getName(); | ||
|
||
return null === $name ? self::NO_NAME : sprintf('"%s"', $name); | ||
} | ||
|
||
public function getStep() | ||
{ | ||
return $this->step; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getStepNumber() | ||
{ | ||
return $this->index + 1; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasDefaultImage() | ||
{ | ||
return File::DEFAULT_IMAGE === $this->getImageName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/* this file is part of pipelines */ | ||
|
||
namespace Ktomk\Pipelines\File\Info; | ||
|
||
use Ktomk\Pipelines\File\Pipeline; | ||
use Ktomk\Pipelines\File\Pipeline\Steps; | ||
|
||
/** | ||
* info about steps (for show output) | ||
* | ||
* info about steps include {@see StepInfo}. | ||
*/ | ||
final class StepsInfo implements \Countable | ||
{ | ||
/** | ||
* @var ?Steps | ||
*/ | ||
private $steps; | ||
|
||
public static function fromPipeline(Pipeline $pipeline = null) | ||
{ | ||
return new self($pipeline ? $pipeline->getSteps() : null); | ||
} | ||
|
||
/** | ||
* @param ?Steps $steps | ||
*/ | ||
public function __construct(Steps $steps = null) | ||
{ | ||
$this->steps = $steps; | ||
} | ||
|
||
/** | ||
* @return array|string[] image names (unique), w/o the default image name | ||
*/ | ||
public function getImageNames() | ||
{ | ||
$images = array(); | ||
foreach (new StepsStepInfoIterator($this->steps) as $info) { | ||
if (false === $info->hasDefaultImage()) { | ||
$images[] = $info->getImageName(); | ||
} | ||
} | ||
|
||
return array_unique($images); | ||
} | ||
|
||
public function getImagesAsString($separator = ', ') | ||
{ | ||
$images = $this->getImageNames(); | ||
|
||
return $images ? implode($separator, $images) : ''; | ||
} | ||
|
||
public function getSummary() | ||
{ | ||
list($names, $annotations) = $this->getNamesAndAnnotations(); | ||
|
||
return sprintf( | ||
'%d%s', | ||
$this->count(), | ||
$names ? ' (' . implode('; ', $this->annotate($names, ' *', $annotations)) . ')' : '' | ||
); | ||
} | ||
|
||
public function count() | ||
{ | ||
return $this->steps ? count($this->steps) : 0; | ||
} | ||
|
||
/** | ||
* @return array [string[] images, string[] names, array<string>[] annotations] | ||
*/ | ||
private function getNamesAndAnnotations() | ||
{ | ||
$names = array(); | ||
$annotations = array(); | ||
|
||
foreach (new StepsStepInfoIterator($this->steps) as $info) { | ||
$names[] = $info->getName(); | ||
$annotations[] = $info->getAnnotations(); | ||
} | ||
|
||
return array($names, $annotations); | ||
} | ||
|
||
/** | ||
* @param array<string> $names | ||
* @param string $annotator | ||
* @param array<string> $annotations | ||
* | ||
* @return array|string[] | ||
*/ | ||
private function annotate(array $names, $annotator, array $annotations) | ||
{ | ||
return array_map(function ($name, $annotations) use ($annotator) { | ||
if ($annotations) { | ||
$name .= $annotator . implode('', $annotations); | ||
} | ||
|
||
return $name; | ||
}, $names, $annotations); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* this file is part of pipelines */ | ||
|
||
namespace Ktomk\Pipelines\File\Info; | ||
|
||
use Ktomk\Pipelines\File\Pipeline\Steps; | ||
|
||
final class StepsStepInfoIterator extends \IteratorIterator | ||
{ | ||
/** | ||
* @var ?Steps | ||
*/ | ||
private $steps; | ||
|
||
/** | ||
* @param ?Steps $steps | ||
*/ | ||
public function __construct(Steps $steps = null) | ||
{ | ||
$this->steps = $steps; | ||
parent::__construct(Steps::fullIter($steps)); | ||
} | ||
|
||
#[\ReturnTypeWillChange] | ||
/** | ||
* @return StepInfo | ||
*/ | ||
public function current() | ||
{ | ||
return new StepInfo(parent::current(), (int)$this->key()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.