Skip to content
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

Merged
merged 3 commits into from Sep 9, 2016
Merged

Using Robo Runner #1179

merged 3 commits into from Sep 9, 2016

Conversation

TeslaDethray
Copy link
Contributor

Extracted from #1177

*/
protected function getDefaultInputDefinition()
private function setRunner()
Copy link
Contributor

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

@TeslaDethray TeslaDethray force-pushed the change/robo_runner branch 6 times, most recently from d58f94f to a01086c Compare September 8, 2016 20:52
@dustinleblanc
Copy link
Contributor

injecting those dependencies like a boss!

{
$this->config = $config;
$this->config = new Config();
$this->setLog(new ConsoleLogger($this->output()));
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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;

Copy link
Contributor Author

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!

@TeslaDethray TeslaDethray force-pushed the change/robo_runner branch 5 times, most recently from d8a216a to fdde1e5 Compare September 9, 2016 00:24
{
$this->config = $config;
$this->config = new Config();
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

  1. Make yourself a new TerminusConfigAwareInterface / Trait.
  2. Make TerminusCommand implement the interface and use the trait.
  3. Share your Config singleton in the container.
  4. 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.

@TeslaDethray TeslaDethray force-pushed the change/robo_runner branch 3 times, most recently from ff888f1 to 3a8f258 Compare September 9, 2016 00:32
$subdirectories = array_merge($subdirectories, $this->locateSubdirectories($dir, $next_namespace));
}
return $subdirectories;
$commands = array_filter(
Copy link
Contributor

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

Copy link
Member

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 ['.'].

@coveralls
Copy link

Coverage Status

Coverage increased (+1.9%) to 15.928% when pulling 691a281 on change/robo_runner into b588e6b on master.

}
}
}
$discovery->setSearchPattern('*Command.php')->setSearchLocations(['.']);
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor

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 😀

Copy link
Contributor

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.

@greg-1-anderson
Copy link
Member

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.

@coveralls
Copy link

coveralls commented Sep 9, 2016

Coverage Status

Coverage remained the same at 14.004% when pulling 223eda4 on change/robo_runner into b588e6b on master.

@TeslaDethray
Copy link
Contributor Author

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.

@ronan
Copy link
Contributor

ronan commented Sep 9, 2016

This is looking sharp. I think any improvements will be minor and don't need to block this PR.

👍 👍 👍

@bensheldon
Copy link
Contributor

👍 excited for the 🛫

@TeslaDethray TeslaDethray merged commit fa9281a into master Sep 9, 2016
@TeslaDethray TeslaDethray deleted the change/robo_runner branch September 9, 2016 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants