Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / src / Commands / ExampleCommands.php
similarity index 51%
rename from vendor/drush/drush/lib/Drush/CommandFiles/ExampleCommandFile.php
rename to vendor/drush/drush/src/Commands/ExampleCommands.php
index ec764dd6f4a795df9bdf5561dd61d5e78eda3ed0..cdb0ea5f0fb6e4db4e129fa7b4fd3ca08479e911 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-namespace Drush\CommandFiles;
+namespace Drush\Commands;
 
 /**
  * @file
@@ -9,44 +9,63 @@ namespace Drush\CommandFiles;
 use Drush\Log\LogLevel;
 use Consolidation\AnnotatedCommand\AnnotationData;
 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
+use Consolidation\OutputFormatters\Options\FormatterOptions;
 
 use Consolidation\AnnotatedCommand\CommandData;
 
-class ExampleCommandFile
+class ExampleCommands extends DrushCommands
 {
     /**
-     * Demonstrate Robo formatters.  Default format is 'table'.
+     * Demonstrate output formatters.  Default format is 'table'.
      *
+     * @command example:table
      * @field-labels
      *   first: I
      *   second: II
      *   third: III
      * @default-string-field second
-     * @usage example:formatters --format=yaml
-     * @usage example:formatters --format=csv
-     * @usage example:formatters --fields=first,third
-     * @usage example:formatters --fields=III,II
+     * @usage example-table --format=yaml
+     * @usage example-table --format=csv
+     * @usage example-table --fields=first,third
+     * @usage example-table --fields=III,II
      * @aliases tf
+     * @hidden
      *
      * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
      */
-    public function exampleTable($options = ['format' => 'table', 'fields' => ''])
+    public function exampleTable($options = ['format' => 'table'])
     {
-        $outputData = [
+        $tableData = [
             'en' => [ 'first' => 'One',  'second' => 'Two',  'third' => 'Three' ],
             'de' => [ 'first' => 'Eins', 'second' => 'Zwei', 'third' => 'Drei'  ],
             'jp' => [ 'first' => 'Ichi', 'second' => 'Ni',   'third' => 'San'   ],
             'es' => [ 'first' => 'Uno',  'second' => 'Dos',  'third' => 'Tres'  ],
         ];
-        return new RowsOfFields($outputData);
+        $data = new RowsOfFields($tableData);
+
+        // Add a render function to transform cell data when the output
+        // format is a table, or similar.  This allows us to add color
+        // information to the output without modifying the data cells when
+        // using yaml or json output formats.
+        $data->addRendererFunction(
+            // n.b. There is a fourth parameter $rowData that may be added here.
+            function ($key, $cellData, FormatterOptions $options, $rowData) {
+                if ($key == 'first') {
+                    return "<comment>$cellData</>";
+                }
+                return $cellData;
+            }
+        );
+
+        return $data;
     }
 
     /**
      * Demonstrate an alter hook with an option
      *
-     * @hook alter example:table
+     * @hook alter example-table
      * @option french Add a row with French numbers.
-     * @usage example:formatters --french
+     * @usage example-table --french
      */
     public function alterFormatters($result, CommandData $commandData)
     {