Drush: examples/sandwich.drush.inc Source File

  1. 7.x doxygen/html/sandwich_8drush_8inc_source.html
  2. master doxygen/html/sandwich_8drush_8inc_source.html
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * Example drush command.
6  *
7  * To run this *fun* command, execute `sudo drush --include=./examples mmas`
8  * from within your drush directory.
9  *
10  * See `drush topic docs-commands` for more information about command authoring.
11  *
12  * You can copy this file to any of the following
13  * 1. A .drush folder in your HOME folder.
14  * 2. Anywhere in a folder tree below an active module on your site.
15  * 3. /usr/share/drush/commands (configurable)
16  * 4. In an arbitrary folder specified with the --include option.
17  * 5. Drupal's /drush or /sites/all/drush folders.
18  */
19 
20 /**
21  * Implements hook_drush_command().
22  *
23  * In this hook, you specify which commands your
24  * drush module makes available, what it does and
25  * description.
26  *
27  * Notice how this structure closely resembles how
28  * you define menu hooks.
29  *
30  * See `drush topic docs-commands` for a list of recognized keys.
31  */
33  $items = array();
34 
35  // The 'make-me-a-sandwich' command.
36  $items['make-me-a-sandwich'] = array(
37  'description' => "Makes a delicious sandwich.",
38  'arguments' => array(
39  'filling' => 'The type of the sandwich (turkey, cheese, etc.). Defaults to ascii.',
40  ),
41  'options' => array(
42  'spreads' => array(
43  'description' => 'Comma delimited list of spreads.',
44  'example-value' => 'mayonnaise,mustard',
45  ),
46  ),
47  'examples' => array(
48  'drush mmas turkey --spreads=ketchup,mustard' => 'Make a terrible-tasting sandwich that is lacking in pickles.',
49  ),
50  'aliases' => array('mmas'),
51  // No bootstrap at all.
52  'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
53  );
54 
55  // The 'sandwiches-served' command. Informs how many 'mmas' commands
56  // completed.
57  $items['sandwiches-served'] = array(
58  'description' => "Report how many sandwiches we have made.",
59  'examples' => array(
60  'drush sandwiches-served' => 'Show how many sandwiches we have served.',
61  ),
62  'aliases' => array('sws'),
63  // Example output engine data: command returns a single keyed
64  // data item (e.g. array("served" => 1)) that can either be
65  // printed with a label (e.g. "served: 1"), or output raw with
66  // --pipe (e.g. "1").
67  'engines' => array(
68  'outputformat' => array(
69  'default' => 'key-value',
70  'pipe-format' => 'string',
71  'label' => 'Sandwiches Served',
72  'require-engine-capability' => array('format-single'),
73  ),
74  ),
75  // No bootstrap at all.
76  'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
77  );
78 
79  // The 'spreads-status' command. Prints a table about available spreads.
80  $items['spreads-status'] = array(
81  'description' => "Show a table of information about available spreads.",
82  'examples' => array(
83  'drush spreads-status' => 'Show a table of spreads.',
84  ),
85  'aliases' => array('sps'),
86  // Example output engine data: command returns a deep array
87  // that can either be printed in table format or as a json array.
88  'engines' => array(
89  'outputformat' => array(
90  'default' => 'table',
91  'pipe-format' => 'json',
92  // Commands that return deep arrays will usually use
93  // machine-ids for the column data. A 'field-labels'
94  // item maps from the machine-id to a human-readable label.
95  'field-labels' => array(
96  'name' => 'Name',
97  'description' => 'Description',
98  'available' => 'Num',
99  'taste' => 'Taste',
100  ),
101  // In table format, the 'column-widths' item is consulted
102  // to determine the default weights for any named column.
103  'column-widths' => array(
104  'name' => 10,
105  'available' => 3,
106  ),
107  'require-engine-capability' => array('format-table'),
108  ),
109  ),
110  // No bootstrap at all.
111  'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
112  );
113 
114  // Commandfiles may also add topics. These will appear in
115  // the list of topics when `drush topic` is executed.
116  // To view this topic, run `drush --include=/full/path/to/examples topic`
117  $items['sandwich-exposition'] = array(
118  'description' => 'Ruminations on the true meaning and philosophy of sandwiches.',
119  'hidden' => TRUE,
120  'topic' => TRUE,
121  'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
122  'callback' => 'drush_print_file',
123  'callback arguments' => array(dirname(__FILE__) . '/sandwich-topic.txt'),
124  );
125 
126  return $items;
127 }
128 
129 /**
130  * Implements hook_drush_help().
131  *
132  * This function is called whenever a drush user calls
133  * 'drush help <name-of-your-command>'. This hook is optional. If a command
134  * does not implement this hook, the command's description is used instead.
135  *
136  * This hook is also used to look up help metadata, such as help
137  * category title and summary. See the comments below for a description.
138  */
139 function sandwich_drush_help($section) {
140  switch ($section) {
141  case 'drush:make-me-a-sandwich':
142  return dt("This command will make you a delicious sandwich, just how you like it.");
143 
144  // The 'title' meta item is used to name a group of
145  // commands in `drush help`. If a title is not defined,
146  // the default is "All commands in ___", with the
147  // specific name of the commandfile (e.g. sandwich).
148  // Command files with less than four commands will
149  // be placed in the "Other commands" section, _unless_
150  // they define a title. It is therefore preferable
151  // to not define a title unless the file defines a lot
152  // of commands.
153  case 'meta:sandwich:title':
154  return dt("Sandwich commands");
155 
156  // The 'summary' meta item is displayed in `drush help --filter`,
157  // and is used to give a general idea what the commands in this
158  // command file do, and what they have in common.
159  case 'meta:sandwich:summary':
160  return dt("Automates your sandwich-making business workflows.");
161  }
162 }
163 
164 /**
165  * Implements drush_hook_COMMAND_validate().
166  *
167  * The validate command should exit with
168  * `return drush_set_error(...)` to stop execution of
169  * the command. In practice, calling drush_set_error
170  * OR returning FALSE is sufficient. See drush.api.php
171  * for more details.
172  */
174  if (drush_is_windows()) {
175  // $name = drush_get_username();
176  // @todo Implement check for elevated process using w32api
177  // as sudo is not available for Windows
180  }
181  else {
182  $name = posix_getpwuid(posix_geteuid());
183  if ($name['name'] !== 'root') {
184  return drush_set_error('MAKE_IT_YOUSELF', dt('What? Make your own sandwich.'));
185  }
186  }
187 }
188 
189 /**
190  * Implements drush_hook_COMMAND().
191  *
192  * The command callback is where the action takes place.
193  *
194  * The function name should be same as command name but with dashes turned to
195  * underscores and 'drush_commandfile_' prepended, where 'commandfile' is
196  * taken from the file 'commandfile.drush.inc', which in this case is
197  * 'sandwich'. Note also that a simplification step is also done in instances
198  * where the commandfile name is the same as the beginning of the command name,
199  * "drush_example_example_foo" is simplified to just "drush_example_foo".
200  * To also implement a hook that is called before your command, implement
201  * "drush_hook_pre_example_foo". For a list of all available hooks for a
202  * given command, run drush in --debug mode.
203  *
204  * If for some reason you do not want your hook function to be named
205  * after your command, you may define a 'callback' item in your command
206  * object that specifies the exact name of the function that should be
207  * called.
208  *
209  * In this function, all of Drupal's API is (usually) available, including
210  * any functions you have added in your own modules/themes.
211  *
212  * @see drush_invoke()
213  * @see drush.api.php
214  */
215 function drush_sandwich_make_me_a_sandwich($filling = 'ascii') {
216  $str_spreads = '';
217  // Read options with drush_get_option. Note that the options _must_
218  // be documented in the $items structure for this command in the 'command'
219  // hook. See `drush topic docs-commands` for more information.
220  if ($spreads = drush_get_option('spreads')) {
221  $list = implode(' and ', explode(',', $spreads));
222  $str_spreads = ' with just a dash of ' . $list;
223  }
224  $msg = dt('Okay. Enjoy this !filling sandwich!str_spreads.',
225  array('!filling' => $filling, '!str_spreads' => $str_spreads)
226  );
227  drush_print("\n" . $msg . "\n");
228 
229  if (drush_get_context('DRUSH_NOCOLOR')) {
230  $filename = dirname(__FILE__) . '/sandwich-nocolor.txt';
231  }
232  else {
233  $filename = dirname(__FILE__) . '/sandwich.txt';
234  }
235  drush_print(file_get_contents($filename));
236  // Find out how many sandwiches have been served, and set
237  // the cached value to one greater.
239  drush_cache_set(drush_get_cid('sandwiches-served'), $served + 1);
240 }
241 
242 /**
243  * Implements drush_hook_COMMAND().
244  *
245  * Demonstrates how to return a simple value that is transformed by
246  * the selected formatter to display either with a label (using the
247  * key-value formatter) or as the raw value itself (using the string formatter).
248  */
250  $served = 0;
251  $served_object = drush_cache_get(drush_get_cid('sandwiches-served'));
252  if ($served_object) {
253  $served = $served_object->data;
254  }
255  // In the default format, key-value, this return value
256  // will print " Sandwiches Served : 1". In the default pipe
257  // format, only the array value ("1") is returned.
258  return $served;
259 }
260 
261 /**
262  * Implements drush_hook_COMMAND().
263  *
264  * This ficticious command shows how a deep array can be constructed
265  * and used as a command return value that can be output by different
266  * output formatters.
267  */
269  return array(
270  'ketchup' => array(
271  'name' => 'Ketchup',
272  'description' => 'Some say its a vegetable, but we know its a sweet spread.',
273  'available' => '7',
274  'taste' => 'sweet',
275  ),
276  'mayonnaise' => array(
277  'name' => 'Mayonnaise',
278  'description' => 'A nice dairy-free spead.',
279  'available' => '12',
280  'taste' => 'creamy',
281  ),
282  'mustard' => array(
283  'name' => 'Mustard',
284  'description' => 'Pardon me, but could you please pass that plastic yellow bottle?',
285  'available' => '8',
286  'taste' => 'tangy',
287  ),
288  'pickles' => array(
289  'name' => 'Pickles',
290  'description' => 'A necessary part of any sandwich that does not taste terrible.',
291  'available' => '63',
292  'taste' => 'tasty',
293  ),
294  );
295 }
296 
297 /**
298  * Command argument complete callback.
299  *
300  * Provides argument values for shell completion.
301  *
302  * @return array
303  * Array of popular fillings.
304  */
306  return array('values' => array('turkey', 'cheese', 'jelly', 'butter'));
307 }

File

doxygen/html/sandwich_8drush_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: examples/sandwich.drush.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d28a4824dc47e487b107a5db32ef43c4.html">examples</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">sandwich.drush.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="sandwich_8drush_8inc.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Example drush command.</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * To run this *fun* command, execute `sudo drush --include=./examples mmas`</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> * from within your drush directory.</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * See `drush topic docs-commands` for more information about command authoring.</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * You can copy this file to any of the following</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *   1. A .drush folder in your HOME folder.</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> *   2. Anywhere in a folder tree below an active module on your site.</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> *   3. /usr/share/drush/commands (configurable)</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *   4. In an arbitrary folder specified with the --include option.</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> *   5. Drupal&#39;s /drush or /sites/all/drush folders.</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * Implements hook_drush_command().</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> * In this hook, you specify which commands your</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"> * drush module makes available, what it does and</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="comment"> * description.</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="comment"> * Notice how this structure closely resembles how</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="comment"> * you define menu hooks.</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="comment"> * See `drush topic docs-commands` for a list of recognized keys.</span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00032"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#afcb354f4e57cf2e9684b2e0124a9fc36">   32</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#afcb354f4e57cf2e9684b2e0124a9fc36">sandwich_drush_command</a>() {</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;  $items = array();</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  <span class="comment">// The &#39;make-me-a-sandwich&#39; command.</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;  $items[<span class="stringliteral">&#39;make-me-a-sandwich&#39;</span>] = array(</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Makes a delicious sandwich.&quot;</span>,</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="stringliteral">&#39;arguments&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;      <span class="stringliteral">&#39;filling&#39;</span> =&gt; <span class="stringliteral">&#39;The type of the sandwich (turkey, cheese, etc.). Defaults to ascii.&#39;</span>,</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    ),</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    <span class="stringliteral">&#39;options&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;      <span class="stringliteral">&#39;spreads&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Comma delimited list of spreads.&#39;</span>,</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;mayonnaise,mustard&#39;</span>,</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;      ),</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    ),</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      <span class="stringliteral">&#39;drush mmas turkey --spreads=ketchup,mustard&#39;</span> =&gt; <span class="stringliteral">&#39;Make a terrible-tasting sandwich that is lacking in pickles.&#39;</span>,</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    ),</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;mmas&#39;</span>),</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    <span class="comment">// No bootstrap at all.</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; <a class="code" href="lib_2Drush_2Boot_2bootstrap_8inc.html#aaa7e693dd78d632c3d0f5baa3ba2d200">DRUSH_BOOTSTRAP_DRUSH</a>,</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;  );</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;  <span class="comment">// The &#39;sandwiches-served&#39; command.  Informs how many &#39;mmas&#39; commands</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;  <span class="comment">// completed.</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;  $items[<span class="stringliteral">&#39;sandwiches-served&#39;</span>] = array(</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Report how many sandwiches we have made.&quot;</span>,</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;      <span class="stringliteral">&#39;drush sandwiches-served&#39;</span> =&gt; <span class="stringliteral">&#39;Show how many sandwiches we have served.&#39;</span>,</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    ),</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;sws&#39;</span>),</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="comment">// Example output engine data:  command returns a single keyed</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="comment">// data item (e.g. array(&quot;served&quot; =&gt; 1)) that can either be</span></div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="comment">// printed with a label (e.g. &quot;served: 1&quot;), or output raw with</span></div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    <span class="comment">// --pipe (e.g. &quot;1&quot;).</span></div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <span class="stringliteral">&#39;engines&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;      <span class="stringliteral">&#39;outputformat&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <span class="stringliteral">&#39;default&#39;</span> =&gt; <span class="stringliteral">&#39;key-value&#39;</span>,</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;        <span class="stringliteral">&#39;pipe-format&#39;</span> =&gt; <span class="stringliteral">&#39;string&#39;</span>,</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        <span class="stringliteral">&#39;label&#39;</span> =&gt; <span class="stringliteral">&#39;Sandwiches Served&#39;</span>,</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        <span class="stringliteral">&#39;require-engine-capability&#39;</span> =&gt; array(<span class="stringliteral">&#39;format-single&#39;</span>),</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;      ),</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    ),</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="comment">// No bootstrap at all.</span></div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; <a class="code" href="lib_2Drush_2Boot_2bootstrap_8inc.html#aaa7e693dd78d632c3d0f5baa3ba2d200">DRUSH_BOOTSTRAP_DRUSH</a>,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;  );</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  <span class="comment">// The &#39;spreads-status&#39; command.  Prints a table about available spreads.</span></div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;  $items[<span class="stringliteral">&#39;spreads-status&#39;</span>] = array(</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Show a table of information about available spreads.&quot;</span>,</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    <span class="stringliteral">&#39;examples&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;      <span class="stringliteral">&#39;drush spreads-status&#39;</span> =&gt; <span class="stringliteral">&#39;Show a table of spreads.&#39;</span>,</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    ),</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    <span class="stringliteral">&#39;aliases&#39;</span> =&gt; array(<span class="stringliteral">&#39;sps&#39;</span>),</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <span class="comment">// Example output engine data:  command returns a deep array</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;    <span class="comment">// that can either be printed in table format or as a json array.</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    <span class="stringliteral">&#39;engines&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;      <span class="stringliteral">&#39;outputformat&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;        <span class="stringliteral">&#39;default&#39;</span> =&gt; <span class="stringliteral">&#39;table&#39;</span>,</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;        <span class="stringliteral">&#39;pipe-format&#39;</span> =&gt; <span class="stringliteral">&#39;json&#39;</span>,</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;        <span class="comment">// Commands that return deep arrays will usually use</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="comment">// machine-ids for the column data.  A &#39;field-labels&#39;</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;        <span class="comment">// item maps from the machine-id to a human-readable label.</span></div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        <span class="stringliteral">&#39;field-labels&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;          <span class="stringliteral">&#39;name&#39;</span> =&gt; <span class="stringliteral">&#39;Name&#39;</span>,</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;          <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Description&#39;</span>,</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;          <span class="stringliteral">&#39;available&#39;</span> =&gt; <span class="stringliteral">&#39;Num&#39;</span>,</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;          <span class="stringliteral">&#39;taste&#39;</span> =&gt; <span class="stringliteral">&#39;Taste&#39;</span>,</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        ),</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;        <span class="comment">// In table format, the &#39;column-widths&#39; item is consulted</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="comment">// to determine the default weights for any named column.</span></div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        <span class="stringliteral">&#39;column-widths&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;          <span class="stringliteral">&#39;name&#39;</span> =&gt; 10,</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;          <span class="stringliteral">&#39;available&#39;</span> =&gt; 3,</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        ),</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <span class="stringliteral">&#39;require-engine-capability&#39;</span> =&gt; array(<span class="stringliteral">&#39;format-table&#39;</span>),</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;      ),</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    ),</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    <span class="comment">// No bootstrap at all.</span></div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; <a class="code" href="lib_2Drush_2Boot_2bootstrap_8inc.html#aaa7e693dd78d632c3d0f5baa3ba2d200">DRUSH_BOOTSTRAP_DRUSH</a>,</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;  );</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;  <span class="comment">// Commandfiles may also add topics.  These will appear in</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;  <span class="comment">// the list of topics when `drush topic` is executed.</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;  <span class="comment">// To view this topic, run `drush --include=/full/path/to/examples topic`</span></div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;  $items[<span class="stringliteral">&#39;sandwich-exposition&#39;</span>] = array(</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;    <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Ruminations on the true meaning and philosophy of sandwiches.&#39;</span>,</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE,</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    <span class="stringliteral">&#39;topic&#39;</span> =&gt; TRUE,</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; <a class="code" href="lib_2Drush_2Boot_2bootstrap_8inc.html#aaa7e693dd78d632c3d0f5baa3ba2d200">DRUSH_BOOTSTRAP_DRUSH</a>,</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    <span class="stringliteral">&#39;callback&#39;</span> =&gt; <span class="stringliteral">&#39;drush_print_file&#39;</span>,</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <span class="stringliteral">&#39;callback arguments&#39;</span> =&gt; array(dirname(__FILE__) . <span class="stringliteral">&#39;/sandwich-topic.txt&#39;</span>),</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  );</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;  <span class="keywordflow">return</span> $items;</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;}</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;<span class="comment"> * Implements hook_drush_help().</span></div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;<span class="comment"> * This function is called whenever a drush user calls</span></div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="comment"> * &#39;drush help &lt;name-of-your-command&gt;&#39;. This hook is optional. If a command</span></div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="comment"> * does not implement this hook, the command&#39;s description is used instead.</span></div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;<span class="comment"> * This hook is also used to look up help metadata, such as help</span></div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;<span class="comment"> * category title and summary.  See the comments below for a description.</span></div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00139"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#a8264cbd615d63688cfe99ee0ef8f4f0f">  139</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#a8264cbd615d63688cfe99ee0ef8f4f0f">sandwich_drush_help</a>($section) {</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;  <span class="keywordflow">switch</span> ($section) {</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;drush:make-me-a-sandwich&#39;</span>:</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;This command will make you a delicious sandwich, just how you like it.&quot;</span>);</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    <span class="comment">// The &#39;title&#39; meta item is used to name a group of</span></div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;    <span class="comment">// commands in `drush help`.  If a title is not defined,</span></div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    <span class="comment">// the default is &quot;All commands in ___&quot;, with the</span></div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    <span class="comment">// specific name of the commandfile (e.g. sandwich).</span></div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    <span class="comment">// Command files with less than four commands will</span></div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    <span class="comment">// be placed in the &quot;Other commands&quot; section, _unless_</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;    <span class="comment">// they define a title.  It is therefore preferable</span></div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <span class="comment">// to not define a title unless the file defines a lot</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    <span class="comment">// of commands.</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;meta:sandwich:title&#39;</span>:</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Sandwich commands&quot;</span>);</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    <span class="comment">// The &#39;summary&#39; meta item is displayed in `drush help --filter`,</span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    <span class="comment">// and is used to give a general idea what the commands in this</span></div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <span class="comment">// command file do, and what they have in common.</span></div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;meta:sandwich:summary&#39;</span>:</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Automates your sandwich-making business workflows.&quot;</span>);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  }</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;}</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;<span class="comment"> * Implements drush_hook_COMMAND_validate().</span></div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;<span class="comment"> * The validate command should exit with</span></div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;<span class="comment"> * `return drush_set_error(...)` to stop execution of</span></div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;<span class="comment"> * the command.  In practice, calling drush_set_error</span></div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;<span class="comment"> * OR returning FALSE is sufficient.  See drush.api.php</span></div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;<span class="comment"> * for more details.</span></div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00173"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#a54dcadf88bda4dec79939fa18cab1c68">  173</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#a54dcadf88bda4dec79939fa18cab1c68">drush_sandwich_make_me_a_sandwich_validate</a>() {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="includes_2environment_8inc.html#a88114295372bcb0ca8dbb5f10b36368e">drush_is_windows</a>()) {</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    <span class="comment">// $name = drush_get_username();</span></div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    <span class="comment">// @todo Implement check for elevated process using w32api</span></div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;    <span class="comment">// as sudo is not available for Windows</span></div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;    <span class="comment">// @see http://php.net/manual/en/book.w32api.php</span></div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    <span class="comment">// @see http://social.msdn.microsoft.com/Forums/en/clr/thread/0957c58c-b30b-4972-a319-015df11b427d</span></div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;  }</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    $name = posix_getpwuid(posix_geteuid());</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;    <span class="keywordflow">if</span> ($name[<span class="stringliteral">&#39;name&#39;</span>] !== <span class="stringliteral">&#39;root&#39;</span>) {</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;MAKE_IT_YOUSELF&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;What? Make your own sandwich.&#39;</span>));</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    }</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;  }</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;}</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;<span class="comment"> * Implements drush_hook_COMMAND().</span></div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;<span class="comment"> * The command callback is where the action takes place.</span></div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;<span class="comment"> * The function name should be same as command name but with dashes turned to</span></div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;<span class="comment"> * underscores and &#39;drush_commandfile_&#39; prepended, where &#39;commandfile&#39; is</span></div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="comment"> * taken from the file &#39;commandfile.drush.inc&#39;, which in this case is</span></div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;<span class="comment"> * &#39;sandwich&#39;. Note also that a simplification step is also done in instances</span></div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;<span class="comment"> * where the commandfile name is the same as the beginning of the command name,</span></div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;<span class="comment"> * &quot;drush_example_example_foo&quot; is simplified to just &quot;drush_example_foo&quot;.</span></div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;<span class="comment"> * To also implement a hook that is called before your command, implement</span></div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;<span class="comment"> * &quot;drush_hook_pre_example_foo&quot;.  For a list of all available hooks for a</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;<span class="comment"> * given command, run drush in --debug mode.</span></div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;<span class="comment"> * If for some reason you do not want your hook function to be named</span></div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;<span class="comment"> * after your command, you may define a &#39;callback&#39; item in your command</span></div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;<span class="comment"> * object that specifies the exact name of the function that should be</span></div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;<span class="comment"> * called.</span></div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;<span class="comment"> * In this function, all of Drupal&#39;s API is (usually) available, including</span></div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;<span class="comment"> * any functions you have added in your own modules/themes.</span></div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;<span class="comment"> * @see drush_invoke()</span></div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;<span class="comment"> * @see drush.api.php</span></div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00215"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#aea9357654295bf3a37faef383d061b4c">  215</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#aea9357654295bf3a37faef383d061b4c">drush_sandwich_make_me_a_sandwich</a>($filling = <span class="stringliteral">&#39;ascii&#39;</span>) {</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;  $str_spreads = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;  <span class="comment">// Read options with drush_get_option. Note that the options _must_</span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;  <span class="comment">// be documented in the $items structure for this command in the &#39;command&#39;</span></div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;  <span class="comment">// hook. See `drush topic docs-commands` for more information.</span></div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;  <span class="keywordflow">if</span> ($spreads = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;spreads&#39;</span>)) {</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;    $list = implode(<span class="stringliteral">&#39; and &#39;</span>, explode(<span class="charliteral">&#39;,&#39;</span>, $spreads));</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;    $str_spreads = <span class="stringliteral">&#39; with just a dash of &#39;</span> . $list;</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;  }</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;  $msg = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Okay. Enjoy this !filling sandwich!str_spreads.&#39;</span>,</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;            array(<span class="stringliteral">&#39;!filling&#39;</span> =&gt; $filling, <span class="stringliteral">&#39;!str_spreads&#39;</span> =&gt; $str_spreads)</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;         );</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;  <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<span class="stringliteral">&quot;\n&quot;</span> . $msg . <span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_NOCOLOR&#39;</span>)) {</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;    $filename = dirname(__FILE__) . <span class="stringliteral">&#39;/sandwich-nocolor.txt&#39;</span>;</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;  }</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    $filename = dirname(__FILE__) . <span class="stringliteral">&#39;/sandwich.txt&#39;</span>;</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;  }</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;  <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(file_get_contents($filename));</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;  <span class="comment">// Find out how many sandwiches have been served, and set</span></div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;  <span class="comment">// the cached value to one greater.</span></div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;  $served = <a class="code" href="sandwich_8drush_8inc.html#a97c7d0d645309157f122dca8052c3243">drush_sandwich_sandwiches_served</a>();</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;  <a class="code" href="includes_2cache_8inc.html#a27a40af68c2a61fdf94b980b953236bf">drush_cache_set</a>(<a class="code" href="includes_2cache_8inc.html#a70613777c5e1a0e258bd0d8e213e0156">drush_get_cid</a>(<span class="stringliteral">&#39;sandwiches-served&#39;</span>), $served + 1);</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;}</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;<span class="comment"> * Implements drush_hook_COMMAND().</span></div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;<span class="comment"> * Demonstrates how to return a simple value that is transformed by</span></div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;<span class="comment"> * the selected formatter to display either with a label (using the</span></div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;<span class="comment"> * key-value formatter) or as the raw value itself (using the string formatter).</span></div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00249"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#a97c7d0d645309157f122dca8052c3243">  249</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#a97c7d0d645309157f122dca8052c3243">drush_sandwich_sandwiches_served</a>() {</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;  $served = 0;</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;  $served_object = <a class="code" href="includes_2cache_8inc.html#adc36ac3b562c67cbf1d7aab89c029694">drush_cache_get</a>(<a class="code" href="includes_2cache_8inc.html#a70613777c5e1a0e258bd0d8e213e0156">drush_get_cid</a>(<span class="stringliteral">&#39;sandwiches-served&#39;</span>));</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;  <span class="keywordflow">if</span> ($served_object) {</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    $served = $served_object-&gt;data;</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;  }</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;  <span class="comment">// In the default format, key-value, this return value</span></div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  <span class="comment">// will print &quot; Sandwiches Served    :  1&quot;.  In the default pipe</span></div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;  <span class="comment">// format, only the array value (&quot;1&quot;) is returned.</span></div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;  <span class="keywordflow">return</span> $served;</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;}</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;<span class="comment"> * Implements drush_hook_COMMAND().</span></div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;<span class="comment"> * This ficticious command shows how a deep array can be constructed</span></div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;<span class="comment"> * and used as a command return value that can be output by different</span></div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;<span class="comment"> * output formatters.</span></div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00268"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#ad658c7276b8b6f85504fabe35d852c00">  268</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#ad658c7276b8b6f85504fabe35d852c00">drush_sandwich_spreads_status</a>() {</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;  <span class="keywordflow">return</span> array(</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;    <span class="stringliteral">&#39;ketchup&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;      <span class="stringliteral">&#39;name&#39;</span> =&gt; <span class="stringliteral">&#39;Ketchup&#39;</span>,</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Some say its a vegetable, but we know its a sweet spread.&#39;</span>,</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;      <span class="stringliteral">&#39;available&#39;</span> =&gt; <span class="charliteral">&#39;7&#39;</span>,</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;      <span class="stringliteral">&#39;taste&#39;</span> =&gt; <span class="stringliteral">&#39;sweet&#39;</span>,</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;    ),</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;    <span class="stringliteral">&#39;mayonnaise&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;      <span class="stringliteral">&#39;name&#39;</span> =&gt; <span class="stringliteral">&#39;Mayonnaise&#39;</span>,</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A nice dairy-free spead.&#39;</span>,</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;      <span class="stringliteral">&#39;available&#39;</span> =&gt; <span class="stringliteral">&#39;12&#39;</span>,</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;      <span class="stringliteral">&#39;taste&#39;</span> =&gt; <span class="stringliteral">&#39;creamy&#39;</span>,</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;    ),</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;    <span class="stringliteral">&#39;mustard&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;      <span class="stringliteral">&#39;name&#39;</span> =&gt; <span class="stringliteral">&#39;Mustard&#39;</span>,</div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Pardon me, but could you please pass that plastic yellow bottle?&#39;</span>,</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;      <span class="stringliteral">&#39;available&#39;</span> =&gt; <span class="charliteral">&#39;8&#39;</span>,</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;      <span class="stringliteral">&#39;taste&#39;</span> =&gt; <span class="stringliteral">&#39;tangy&#39;</span>,</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;    ),</div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;    <span class="stringliteral">&#39;pickles&#39;</span> =&gt; array(</div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;      <span class="stringliteral">&#39;name&#39;</span> =&gt; <span class="stringliteral">&#39;Pickles&#39;</span>,</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A necessary part of any sandwich that does not taste terrible.&#39;</span>,</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;      <span class="stringliteral">&#39;available&#39;</span> =&gt; <span class="stringliteral">&#39;63&#39;</span>,</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;      <span class="stringliteral">&#39;taste&#39;</span> =&gt; <span class="stringliteral">&#39;tasty&#39;</span>,</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;    ),</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;  );</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;}</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;<span class="comment"> * Command argument complete callback.</span></div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;<span class="comment"> * Provides argument values for shell completion.</span></div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;<span class="comment"> * @return array</span></div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;<span class="comment"> *   Array of popular fillings.</span></div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00305"></a><span class="lineno"><a class="code" href="sandwich_8drush_8inc.html#ae369854dbda78d3d613047b9983f6775">  305</a></span>&#160;<span class="keyword">function</span> <a class="code" href="sandwich_8drush_8inc.html#ae369854dbda78d3d613047b9983f6775">sandwich_make_me_a_sandwich_complete</a>() {</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;  <span class="keywordflow">return</span> array(<span class="stringliteral">&#39;values&#39;</span> =&gt; array(<span class="stringliteral">&#39;turkey&#39;</span>, <span class="stringliteral">&#39;cheese&#39;</span>, <span class="stringliteral">&#39;jelly&#39;</span>, <span class="stringliteral">&#39;butter&#39;</span>));</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 8 2014 09:04:54 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>