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
Using Robo Runner #1179
Using Robo Runner #1179
Conversation
1cad5ed
to
7a43ec6
Compare
*/ | ||
protected function getDefaultInputDefinition() | ||
private function setRunner() |
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.
A setter should probably explicitly accept an argument, it will be easier to test and also refactor later
d58f94f
to
a01086c
Compare
injecting those dependencies like a boss! |
a01086c
to
309d881
Compare
{ | ||
$this->config = $config; | ||
$this->config = new Config(); | ||
$this->setLog(new ConsoleLogger($this->output())); |
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.
Might want to inject a logger; I'd think you would definitely want to inject the Config() object, since setting that up probably involves parsing files.
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.
How can I inject things into the commands Robo\Runner instantiates?
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.
That's a reasonable request! ;)
Robo is designed to use league/container inflection to automatically inject your dependencies. Just make your class instantiate a SomethingAwareInterface, and the inflector will call the appropriate set method provided by SomethingAwareTrait in the same class.
However, you should not be REQUIRED to use league/container to use the Robo runner. I'll make a small change to the runner to allow you to pass in already-constructed command classes.
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.
Also, this line ($this->setLog(new ConsoleLogger($this->output()));
) is the source of the verbosity bug. What's happening here is that Robo injects the output object via the technique above ^^; it uses setOutput() in OutputAwareTrait, since you implement OutputAwareInterface. The result of this is that $this->output() is not available in your constructor, as the constructor is called to set up the object before its setOutput() method is called.
n.b. if you construct your own objects, you'll need to inject the input and output objects yourself.
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.
I should also mention that Robo sets up its own logger object, so if you just make TerminusCommand implement LoggerAwareInterface, then Robo will inject a working logger for you, available via protected $logger;
, which is in LoggerAwareTrait.
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.
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
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.
Aha, THIS is just the thing I needed! WOOT!
d8a216a
to
fdde1e5
Compare
{ | ||
$this->config = $config; | ||
$this->config = new Config(); |
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.
Injecting this means that I won't be able to let Robo work its inputter/outputter/logger-injecting magic.
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.
Would using an ioc container make a difference? My brain starts to hurt when I think about service containers (and the yaml loading mess of Symfony's container makes it worse). If an upstream change in Robo would make it easier, we could submit a PR there too. For now, newing up an object in the constructor isn't the end of the world, but we should fight it like the plague before we take on too much tech debt.
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.
It's really not that hard. Robo's injecting magic is designed to be extensible.
- Make yourself a new TerminusConfigAwareInterface / Trait.
- Make TerminusCommand implement the interface and use the trait.
- Share your Config singleton in the container.
- Add an inflector to the league/container at startup to set your config object on anything that implements TerminusConfigAwareInterface.
For that matter, you might be able to just get away with using Robo's config object. It has getters and setters; might work. Or, subclass it and use Robo's ConfigAwareInterface / ConfigAwareTrait.
Yes, Robo rocks. I'll show you how to do (3) and (4) tomorrow. It's just a few easy lines of code, because league/container rocks. It's a pity that so many people try to learn DI with the Symfony container, because I agree that Symfony service containers are prone to making heads hurt. But it doesn't have to be painful.
ff888f1
to
3a8f258
Compare
$subdirectories = array_merge($subdirectories, $this->locateSubdirectories($dir, $next_namespace)); | ||
} | ||
return $subdirectories; | ||
$commands = array_filter( |
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.
I <3 this functional waterfall of delight
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.
I love it too -- even though I feel bad that you had to write it. ;) You can take it out when you update to annotated commands 1.3.1 and set the search locations to empty instead of ['.'].
3a8f258
to
411ec1b
Compare
411ec1b
to
691a281
Compare
} | ||
} | ||
} | ||
$discovery->setSearchPattern('*Command.php')->setSearchLocations(['.']); |
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.
I'll give you a new CommandFileDiscovery that will work right if you change this to setSearchLocations([]);
. The problem with .
as a search location is it makes the command discovery object search each location twice, because it always searches the base directory atm.
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.
I pushed a new consolidation/annotated-command version 1.3.1 that supports this.
… objects. Demonstrate verbose/debug output with some temporary code in the Art command.
@@ -228,6 +218,22 @@ private static function getTerminusScript() | |||
} | |||
|
|||
/** | |||
* Ensures that directory paths work in any system |
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.
I think this might blow up Cygwin, but I haven't used Cygwin in many years and don't quite remember.
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.
Hopefully with bash support in Win10 on it's way we will have less cause to care 😀
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.
I have Cygwin installed on a VirtualBox, so let me know if you'd like me to test.
I pushed a commit to improve DI here. I will also fix up the unit tests, but first I want to make the Robo API a bit better, so we can clean up things here a little more. |
I fixed a couple bugs, brushed up the internal docs, and fixed the unit tests. Although there are still a few things that can be done to further enhance Terminus 1.0's use of Robo, I think this PR should be merged before we have the time to discuss those changes because it is blocking the work of others. |
This is looking sharp. I think any improvements will be minor and don't need to block this PR. 👍 👍 👍 |
👍 excited for the 🛫 |
Extracted from #1177