cdb0ea5f0fb6e4db4e129fa7b4fd3ca08479e911
[yaffs-website] / vendor / drush / drush / src / Commands / ExampleCommands.php
1 <?php
2 namespace Drush\Commands;
3
4 /**
5  * @file
6  *   Set up local Drush configuration.
7  */
8
9 use Drush\Log\LogLevel;
10 use Consolidation\AnnotatedCommand\AnnotationData;
11 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
12 use Consolidation\OutputFormatters\Options\FormatterOptions;
13
14 use Consolidation\AnnotatedCommand\CommandData;
15
16 class ExampleCommands extends DrushCommands
17 {
18     /**
19      * Demonstrate output formatters.  Default format is 'table'.
20      *
21      * @command example:table
22      * @field-labels
23      *   first: I
24      *   second: II
25      *   third: III
26      * @default-string-field second
27      * @usage example-table --format=yaml
28      * @usage example-table --format=csv
29      * @usage example-table --fields=first,third
30      * @usage example-table --fields=III,II
31      * @aliases tf
32      * @hidden
33      *
34      * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
35      */
36     public function exampleTable($options = ['format' => 'table'])
37     {
38         $tableData = [
39             'en' => [ 'first' => 'One',  'second' => 'Two',  'third' => 'Three' ],
40             'de' => [ 'first' => 'Eins', 'second' => 'Zwei', 'third' => 'Drei'  ],
41             'jp' => [ 'first' => 'Ichi', 'second' => 'Ni',   'third' => 'San'   ],
42             'es' => [ 'first' => 'Uno',  'second' => 'Dos',  'third' => 'Tres'  ],
43         ];
44         $data = new RowsOfFields($tableData);
45
46         // Add a render function to transform cell data when the output
47         // format is a table, or similar.  This allows us to add color
48         // information to the output without modifying the data cells when
49         // using yaml or json output formats.
50         $data->addRendererFunction(
51             // n.b. There is a fourth parameter $rowData that may be added here.
52             function ($key, $cellData, FormatterOptions $options, $rowData) {
53                 if ($key == 'first') {
54                     return "<comment>$cellData</>";
55                 }
56                 return $cellData;
57             }
58         );
59
60         return $data;
61     }
62
63     /**
64      * Demonstrate an alter hook with an option
65      *
66      * @hook alter example-table
67      * @option french Add a row with French numbers.
68      * @usage example-table --french
69      */
70     public function alterFormatters($result, CommandData $commandData)
71     {
72         if ($commandData->input()->getOption('french')) {
73             $result['fr'] = [ 'first' => 'Un',  'second' => 'Deux',  'third' => 'Trois'  ];
74         }
75
76         return $result;
77     }
78 }