Comments

greg.1.anderson’s picture

As 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.

msonnabaum’s picture

If 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/

clemens.tolboom’s picture

Status: Active » Needs review
StatusFileSize
new3.18 KB

The 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=yaml printing the full $conf array but it only prints the values one by one. This has to do with the implementation of drush_variable_get()

robloach’s picture

BTW, 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.

moshe weitzman’s picture

Status: Needs review » Needs work

Most 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

clemens.tolboom’s picture

@moshe weitzman you are right about the requirement.

+++ b/includes/output.inc
@@ -393,6 +396,11 @@ function drush_json_decode($var) {
+function drush_yaml_encode($var) {
drush_environment_yaml_lib()
try {
+  $dumper = new sfYamlDumper();
+  return $dumper->dump($var);
}
catch {
  ??
}
+}
+

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.

clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new3.87 KB

I 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.

moshe weitzman’s picture

Status: Needs review » Needs work

Looks 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?

robloach’s picture

StatusFileSize
new2.73 KB

What 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().

clemens.tolboom’s picture

@moshe weitzman
For drush.entity.inc we print output like this

  drush_print_pipe(drush_format($result));
  drush_print(drush_format($result));

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 ;)

greg.1.anderson’s picture

drush_print_pipe is supposed to print uniform output designed for use by scripts, so sending formatted output to it is, in fact, wrong.

msonnabaum’s picture

I like Rob's idea of making this more pluggable. Maybe we need another issue to track fixing how we handle formats?

msonnabaum’s picture

To clarify, I like the idea of making it pluggable, but I still think we should be responsible for providing yaml.

clemens.tolboom’s picture

Just 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 ... WTF

To 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

clemens.tolboom’s picture

I 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.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev

Closed #1912630: Add a yaml output format as a duplicate of this issue.

greg.1.anderson’s picture

Added 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.

greg.1.anderson’s picture

Assigned: clemens.tolboom » Unassigned

Unassigning. Clemens can take this if he likes, of course, but perhaps someone else might also want to help out here.

moshe weitzman’s picture

Title: Add yaml (like) output as a --format » Automatically download Symfony YAML component
Category: feature » bug
Issue tags: +Release blocker

We currently fatal when running dr topic docs-output-formats outside 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.

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB

Attached 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

"require": {
        "php": ">=5.3.3"
    },

Furthermore we support PEAR downloads through drush_lib_fetch().

clemens.tolboom’s picture

StatusFileSize
new3.96 KB

Removed 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]

greg.1.anderson’s picture

StatusFileSize
new331 bytes
new4.39 KB

This 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.

clemens.tolboom’s picture

StatusFileSize
new2.99 KB
new3.81 KB

Nice 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.

moshe weitzman’s picture

Status: Needs review » Needs work

Looking good.

+ // This is invoked twice due to normal+piped output generation

We 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'

clemens.tolboom’s picture

StatusFileSize
new3.87 KB

Patch 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 generation
just to make sure invocation is fixed.

And made the probing 'debug' level.

(to be continued)

clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new3.43 KB

My bad ... it had nothing to do with class loader.

+++ b/commands/core/outputformat/yaml.inc
@@ -5,6 +5,25 @@
+      require_once "$path/Dumper.php";
+      require_once "$path/Inline.php";
+      require_once "$path/Escaper.php";

Needed a DRUSH_BASE_PATH

clemens.tolboom’s picture

StatusFileSize
new3.84 KB

I 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()

+++ b/commands/core/outputformat/yaml.inc
@@ -24,9 +40,57 @@ class drush_outputformat_yaml extends drush_outputformat {
+  }
+  require_once $file;
+  return TRUE;
+}

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

moshe weitzman’s picture

Now that I think of it, we can just commit the lib into drush just as Drupal core has done.

clemens.tolboom’s picture

Good 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.

moshe weitzman’s picture

Drush 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.

clemens.tolboom’s picture

Assigned: clemens.tolboom » Unassigned

Well let's fix this one then :-)

I start following on #1316322: Add PSR-0 autoloader to drush

moshe weitzman’s picture

Status: Needs review » Fixed
Issue tags: -Release blocker

I 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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.