-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #65: Allow commands to call other commands #65
Conversation
This introduces the new |
4ebc3f8
to
2647005
Compare
if (is_string($calls)) { | ||
$calls = explode(',', static::convertListToCommaSeparated($calls)); | ||
} | ||
$this->calls = array_filter($calls); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe array-merge these together, so folks can use multiple @calls
in addition to csv, if they prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'd prefer that. I briefly attempted this but wasn't quite sure how to access multiple @calls
values, each usage appeared to overwrite the previous.
src/AnnotatedCommand.php
Outdated
protected function executeCallsCommands() { | ||
if ($this->getCalls()) { | ||
foreach ($this->getCalls as $command_name) { | ||
// @todo validate that $command_name exists in this application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the interesting part. The $application field of Symfony Console's command class is private. 😢
We could override setApplication to cache our own copy of it. Not super great.
$command = $this->getApplication()->find($command_name); | ||
if (!$command) { | ||
/** @var LoggerInterface $logger */ | ||
//$logger->warning("Command $command_name does not exist. Skipping."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a logging mechanism available?
@greg-1-anderson Let's make a list of what it will take to merge this in.
|
*/ | ||
protected function processCalls($tag) | ||
{ | ||
$this->commandInfo->setCalls((string)$tag->getDescription()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are multiple @Calls annotations, this function will be called multiple times. Currently, this implementation overwrites via setCalls()
. It could also call getCalls() first and merge. Might want to move where the csv is converted to an array here, maybe.
I have reservations about I tend to think that this implementation should be abandoned, and we should make it easier for one command to call another via PHP. |
@greg-1-anderson I'm ok with abandoning this implementation and following up with a different plan in #64. I mostly want to avoid: <?php
/**
* @command tests:all
*/
public function testsAll() {
$result = $invoker->invoke('tests:behat');
if (!$result) {
return 1;
}
$result = $invoker->invoke('tests:phpunit');
if (!$result) {
return 1;
}
$result = $invoker->invoke('tests:custom');
if (!$result) {
return 1;
}
} |
No description provided.