Closed (fixed)
Project:
Drush
Version:
8.x-6.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Dec 2011 at 12:49 UTC
Updated:
23 May 2013 at 21:44 UTC
Jump to comment: Most recent file
Comments
Comment #1
greg.1.anderson commentedAs I mention at http://drupal.org/node/1005480#comment-5345764, it would be best to factor, enhance and use the --format code from variable-get and variable-set here.
Comment #2
msonnabaum commentedIf we do this (which I'm totally fine with), I think we should pull in symfony's yaml lib: http://components.symfony-project.org/yaml/
Comment #3
clemens.tolboomThe attached patch provide for YAML.
Some remarks about adding this patch.
Adding the library to environment.inc has a high DRY (do not repeat yourself) alert.
- I need to add new similar defines
- duplicate and tweak the code from drush_environment_table_lib().
- as this is only the second library this is not a big deal but I guess we need to create an issue for this for future refactoring.
I expected the output of
drush vget --format=yamlprinting the full $conf array but it only prints the values one by one. This has to do with the implementation ofdrush_variable_get()Comment #4
robloachBTW, in the Symfony module, I put together a drush_symfony_download() to download Symfony. It also installs all Symfony vendors too. Might be good to update that to Drush Make and Drush 5.x though.
Comment #5
moshe weitzman commentedMost people don't care about YAML. We need to download the lib when it is needed, and not make it a requirement of the bootstrap.
The error msg when unsuccessful still talks about ConsoleTable
Comment #6
clemens.tolboom@moshe weitzman you are right about the requirement.
Invoke drush_environment_yaml_lib() here?
@Rob Loach thanks for the pointer. But not sure what to do with it. In #3 I'm trying to say drush needs some better library management.
Comment #7
clemens.tolboomI removed the bootstrap download. Only environment.inc and output.inc are now touched.
I tried to make the code a little more generic so we can incorporate a lib quicker the next time.
Comment #8
moshe weitzman commentedLooks much better.
Do we really need the awkward static $success?
The project is called Symfony, not Symphony. Lets standardize the spelling.
Lets make a function that gets passed $settings and returns the custom error message. Any existing libs should use it?
Comment #9
robloachWhat if we had something like this to extend how Drush formats variables? I've also been putting some time into the Symfony module to make registering/downloading the library easy. If we had the attached patch in Drush, then we could expose the YAML formatter in symfony.drush.inc with drush_format_yaml().
Comment #10
clemens.tolboom@moshe weitzman
For drush.entity.inc we print output like this
It that wrong? Then we can get rid of the $success. Otherwise the yaml (or other formatter lib) is called twice or more times. Only ConsoleTable is loaded on bootstrap.
A general function is much better but I did not want to clone library module. But yeah let's make it a function.
@Rob Loach
In writing #1396178: Add properties output as a --format I also wanted a hook like structure. So that patch is cool ... but shouldn't that be in another issue? See #1396524: drush vget should spit out one structure so ie vget --json gives one string instead of only values as a side note ;)
Comment #11
greg.1.anderson commenteddrush_print_pipe is supposed to print uniform output designed for use by scripts, so sending formatted output to it is, in fact, wrong.
Comment #12
msonnabaum commentedI like Rob's idea of making this more pluggable. Maybe we need another issue to track fixing how we handle formats?
Comment #13
msonnabaum commentedTo clarify, I like the idea of making it pluggable, but I still think we should be responsible for providing yaml.
Comment #14
clemens.tolboomJust a note about the location for the libraries.
- I just downloaded 7.x-4.5 (as this is the recommended version)
- Installed it under /usr/local/lib and symlinked /usr/local/bin accordingly
- Next my test user runs
drush --version- drush then tries to download and install Console_Table under
/usr/local/lib/drush/includes... WTFTo make the library install flow workable for ie yaml the location should be ~/.drush/libaries or something similar as yaml support is only installed when needed as @moshe weitzman said in #5
Comment #15
clemens.tolboomI moved Rob Loach patch to #1441026: Add a hook_drush_output_formats
I'm not sure what we can do with the drush_format_yaml as suggested in #9 as it would require the symphony module to provide for yaml support. It would relieve drush for the library management but ... hmmm.
Comment #16
greg.1.anderson commentedClosed #1912630: Add a yaml output format as a duplicate of this issue.
Comment #17
greg.1.anderson commentedAdded a yaml output format in #1912628: Adapt other core Drush commands to output engines #14. Note, however, that the code committed only works when a Drupal-8 site is bootstrapped. We need to either use Symphony to load the yaml classes when D8 is not available, or perhaps switch to a different method of producing yaml, perhaps similar to the technique used in http://drupal.org/node/1364808#comment-6018126.
Comment #18
greg.1.anderson commentedUnassigning. Clemens can take this if he likes, of course, but perhaps someone else might also want to help out here.
Comment #19
moshe weitzman commentedWe currently fatal when running
dr topic docs-output-formatsoutside of a D8 site. Marking as a release blocker. I'm inclined to go with something like #7, with updated yaml outputformat engine instead of output.inc changes. Anyone want to take this on?FYI, output formats are now engines so I think we took care of #9.
Comment #20
clemens.tolboomComment #21
clemens.tolboomAttached patch reused the code from #7.
The resulting code is a little clumsy but we need to support non PHP-5.3 installations so cannot use https://github.com/symfony/Yaml as that requires
Furthermore we support PEAR downloads through
drush_lib_fetch().Comment #22
clemens.tolboomRemoved bad code.
[edit]
< + if (is_dir('lib/YYaml')) {
< + require_once 'lib/Yaml/Dumper.php';
< + require_once 'lib/Yaml/Inline.php';
< + require_once 'lib/Yaml/Escaper.php';
< + }
[/edit]
Comment #23
greg.1.anderson commentedThis worked great the first time I used it, but returned an error on the second run. Returning TRUE at the end of the yaml load function fixed the problem. This code looks great to me, and I think we can go with it; however, Drush already requires PHP 5.3.5 in bootstrap.inc, so I think that the Symfony yaml loader could also be used, if its simpler and there are no other impediments to its use.
Comment #24
clemens.tolboomNice to know we can rely on PHP 5.3.5
Then it comes down to how do we download the same version as D8 uses from https://github.com/symfony/Yaml or other ways.
http://pear.symfony-project.com/ only supports up to Yaml-1.0.6
So the best option is to follow the instructions from http://symfony.com/doc/current/components/yaml/introduction.html using git fetching a zip.
Comment #25
moshe weitzman commentedLooking good.
+ // This is invoked twice due to normal+piped output generationWe shouldn't doing double output now that we have outputformat engines
Remove
+ drush_log("Probing $file");, IMO. If you think we really need it, it should be log level 'debug'Comment #26
clemens.tolboomPatch from #24 fails on D7 while patch from #23 works.
This has to do with class loader stuff. But I like to have the same version of Yaml as D8 has.
In the mean time added a log line for the
+ // This is invoked twice due to normal+piped output generationjust to make sure invocation is fixed.
And made the probing 'debug' level.
(to be continued)
Comment #27
clemens.tolboomMy bad ... it had nothing to do with class loader.
Needed a DRUSH_BASE_PATH
Comment #28
clemens.tolboomI have:
- cleaned up the multi call test as mentioned in #25
- removed the is_dir test as tests were done already
- removing the package.xml was PEAR related code
- The $success is not static so also removed from code @ end of drush_environment_yaml_lib()
Why do we do this? It make a still missing file inclusion fatal which is good in a way but we try to include this again in line ~19
Comment #29
moshe weitzman commentedNow that I think of it, we can just commit the lib into drush just as Drupal core has done.
Comment #30
clemens.tolboomGood point. But then I prefer the composer route to install the dependencies by hand.
For the debian package the libs need to be included if allowed or added as a deb-dependency.
This way drush provides the plumbing but has no maintenance hassle.
Comment #31
moshe weitzman commentedDrush doesn't use Composer at this time, and it won't start doing so in this issue. Feel free to reroll and advocate at #1316322: Add PSR-0 autoloader to drush. For this issue, we should commit YAML into our repo.
Comment #32
clemens.tolboomWell let's fix this one then :-)
I start following on #1316322: Add PSR-0 autoloader to drush
Comment #33
moshe weitzman commentedI mashed this up and committed the Symfony component (v2.2.1) and edited the formatter accordingly. There are some open questions. If anyone wants to discuss them pr provide a patch, please reopen this issue. I'd welcome that.
1. I put the YAML component in /lib. This is the first library that lives there and isn't fetched by Drush during runtime.
2. In the diff, see the class_exists() at the top of yaml.inc. This is what I used to make this formatter work inside and outside of Drupal. There may be cleaner ways to do this.
3. There is an empty @code section in the Doxygen of the formatter.
4. It look like there is no YAML test in outputformatTest.php