Grayside.Org - drush http://grayside.org/category/terms/drush en Drush Snippets: Menu Trace http://grayside.org/2012/08/drush-snippets-menu-trace <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Random snippet of the day, find out what modules are involved in building out a given menu route definition. When you type a <span class="caps">URI</span> into your browser, Drupal&#8217;s menu routing system connects that to your page content by processing the path into instructions for how to build the&nbsp;page.</p> <p>To use this script, copy the text or clone from github as a file, make it executable. It will automatically run with <code>drush php-script</code>. You can use <code>--verbose</code> for &#8220;full array notation&#8221; of each module&#8217;s change to the menu route. Or you can just use <code>--pipe</code> to get a list of modules and go look at the code&nbsp;directly.</p> <script src="https://gist.github.com/3326438.js"> </script> <p>In theory this should work with Drupal 7, but I haven&#8217;t gotten around to testing it&nbsp;yet.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/drupal6">drupal6</a></div><div class="field-item odd"><a href="/category/terms/drush">drush</a></div><div class="field-item even"><a href="/category/1/snippet">snippet</a></div><div class="field-item odd"><a href="/taxonomy/term/1">drupal</a></div></div></div> Sat, 11 Aug 2012 19:08:54 +0000 Grayside 99 at http://grayside.org http://grayside.org/2012/08/drush-snippets-menu-trace#comments Extending Drush Commands http://grayside.org/2012/04/extending-drush-commands <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>The other day around the office, I was surprised to discover not everyone realizes that you can do some crazy stuff around extending drush commands.</p> <p>First step: Read the documentation. Drush is intentionally written to be a command-line foil for Drupal, and if you&#8217;ve built a module, a few minutes digging into the well-done docs will go a long way. Check out the <a href="http://api.drush.ws">Drush <span class="caps">API</span></a> if you are of a mind, or for a more focused burst of hook goodness, get out your terminal and type:</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">$&gt; drush topic docs-api</pre></div> </div> <p>Once you have a grasp of the fine hooks you can use to piggy-back on and around any Drush command, you can take it to the next level.</p> <h3>Adding&nbsp;Options</h3> <p>Adding options to a Drush command allows you to create more sophisticated, controllable extensions to core command behaviors.</p> <p>There are several ways of doing this.</p> <h4>The command allows this&nbsp;already</h4> <p>Let&#8217;s not make this too complicated. Commands are sometimes intended as passthru mechanisms, such as <code>drush rsync</code>. How does it accept any rsynch command? It has a command definition that includes <span class="geshifilter"><code class="text geshifilter-text">allow-additional-options =&gt; TRUE</code></span>.</p> <h4>The user operates in non-strict&nbsp;mode</h4> <p>If the developer can set a flag, so can the user! You might have already seen this warning:</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">Unknown option: --simple. &nbsp;See `drush help help` for available options. To suppress this error, add the option --strict=0.</pre></div> </div> <p>This means that any time the user adds <span class="geshifilter"><code class="text geshifilter-text">--strict=0</code></span> to a drush command invocation (or to their <a href="http://drush.ws/examples/example.drushrc.php">drushrc file</a> for that specific command), your drush code can use <a href="http://api.drush.ws/api/drush/includes!context.inc/function/drush_get_option/5.x"><code>drush_get_option()</code></a> to access the submitted value.</p> <h4>But for the clever command&nbsp;extension&#8230;</h4> <p>You&#8217;ll want to implement <a href="http://api.drush.ws/api/drush/docs!drush.api.php/function/hook_drush_help_alter/5.x"><code>hook_drush_help_alter()</code></a>. Using this hook, you can add new options to a drush command that will be be qualified as &#8220;strict&#8221;, <strong>and</strong> will even show up in the <em>help</em> entry for the command in the user&#8217;s system.</p> <h3>Why didn&#8217;t you show source&nbsp;code?</h3> <p>Well, I had this small idea in mind, but it evolved rather quickly into a legitimate project. Go check out <a href="http://drupal.org/project/drush_notify">Drush Notify</a>. It&#8217;s pretty Ubuntu-specific out the gate, but it serves as a great example of a powerful drush &#8220;extension&#8221; that defines no&nbsp;commands.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/drush">drush</a></div></div></div> Sat, 21 Apr 2012 07:21:54 +0000 Grayside 98 at http://grayside.org http://grayside.org/2012/04/extending-drush-commands#comments Configure Drush in Your Git Repository http://grayside.org/2011/08/configure-drush-your-git-repository <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>One of the neat features of Drush is it&#8217;s configurability. Setting the defaults for various behaviors and command options allows you to build really simplified, specialized workflows. You can create personal settings defaults by dropping a `drushrc.php` file in one of the places Drush will look, such as inside a .drush folder of your home&nbsp;directory.</p> <p>It turns out this little capability has provided some very simple wins for developers at <a href="http://www.goingon.com">GoingOn</a>. We pass around our projects and sites as a subdirectory of a Git repository that contains various things, such as documentation, deployment tools, and drush commands. Unfortunately, this slightly irregular practice disconnects Drush from the Drupal site and excludes those drush commands from the standard directories drush&nbsp;scans.</p> <p>We fix this by making Drush aware of the Git Repo. There is a command-line script you can use to check if you are anywhere in a Git repository. By configuring Drush to check for a Git Repo on every drush bootstrapping, we give Drush a chance to pick up a bonus, repository-specific Drush config&nbsp;file.</p> <p><em>Add this snippet to your drushrc.php&nbsp;file:</em></p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/exec"><span style="color: #990000;">exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'git rev-parse --show-toplevel 2&gt; /dev/null'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$repo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/drushrc.php'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'include'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/commands'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias-path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/aliases'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>This script checks the current directory for participation in a git repository. If there is one, it looks at the root of the git repository for a &#8216;.drushrc.php&#8217; file to provide repo-specific instructions to Drush. We use this to configure paths to external resources that can vary by code version, as well as setting the Drupal site root for the Drupal site sihpped with that particular&nbsp;repository.</p> <p>The last line also seeks out a `scripts/` directory in the repository root, which it will scan recursively for any files ending in `.drush.inc`. This allows us to ship versioned drush commands with each repo instead of documenting a complex individual installation&nbsp;process.</p> <p>There are many other things you can do with a little poking about in the options for a drushrc file, to learn more start with the <a href="http://drush.ws/examples/example.drushrc.php">drushrc.php example</a>.</p> <p><strong>Update 7/16/2012</strong>: Updated code example to the same provided in Drush docs. You can now leverage this trick outside the root directory of your code repository. Also removed not applicable git context resulting in invalid configuration&nbsp;paths.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/drush">drush</a></div><div class="field-item even"><a href="/taxonomy/term/86">git</a></div></div></div> Sat, 20 Aug 2011 06:53:18 +0000 Grayside 93 at http://grayside.org http://grayside.org/2011/08/configure-drush-your-git-repository#comments Drush with Bash Aliases http://grayside.org/2010/06/drush-bash-aliases <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I&#8217;ve been looking for some decent ways of managing the use of modules hosted in random Features Servers. Particularly, how do I use Drush as seamlessly with a Features Server as it works with Drupal.Org?</p> <p>It turns out that Drush has a lot of special options buried in the <em>pm-download (dl)</em> command, the very Drush maneuver most helpful for my goal. Naturally, these options can be included in a Bash Alias for Drush.</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">alias dds='drush --source=http://code.developmentseed.org/fserver dl'</pre></div> </div> <p>This alias specifically searches DevSeed&#8217;s features server for projects. Slide it into your <a href="http://www.linux.org/lessons/beginner/l6/lesson6a.html"><em>.bashrc</em> file</a>. Now a quick <em>$&gt; dds fserver</em> works like a charm.</p> <p>I still think <a href="http://grayside.org/2010/05/drush-and-features-servers">project repositories</a> like Ubuntu&#8217;s package repos (or really, Arch repositories like Core, Extra, and Aur) have a lesson for us. But that can wait on the smoothing out of functionality like <em>&#8211;destination</em>, which allows you to say where a project will be saved, but not with the same grace as Drupal.Org projects and the <em>modules/contrib/</em>&nbsp;directory.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/drush">drush</a></div><div class="field-item odd"><a href="/category/terms/features-servers">features-servers</a></div></div></div> Thu, 10 Jun 2010 06:18:40 +0000 Grayside 80 at http://grayside.org http://grayside.org/2010/06/drush-bash-aliases#comments Drush and Features Servers http://grayside.org/2010/05/drush-and-features-servers <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Feature Servers have great potential to help structure the use of code sourced outside the formal ecosphere around Drupal.Org this has it&#8217;s pro&#8217;s and con&#8217;s, but I already see their usefulness in providing a little more structure to issue-queue code exchanges and organization-internal modules. So let&#8217;s bring Drush into this and boost the ease of use of that usefulness another step up.</p> <p><em>For those who need more catching up:</em><br /> Features are a special kind of <a href="http://drupal.org">Drupal</a> module built on the <a href="http://drupal.org/project/features">features</a> project. They allow you to easily export configuration from your site into a module usable on any site. Modules downloaded from a <a href="http://developmentseed.org/blog/2009/jun/24/distributed-feature-servers-drupal">Features Server</a> are the next best thing to one posted to Drupal.org. <a href="http://sf2010.drupal.org/conference/sessions/managing-and-deploying-configuration-exportables-and-features-module">DrupalConSF has a great video</a>.</p> <h3>Current State</h3> <p>The rise of Feature Servers, and perhaps other types of code release repositories would benefit from a little Drush magic. The little-documented option of <strong>&#8211;source</strong> is a starting place:</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">drush --source=http://code.developmentseed.org/fserver/ dl fserver </pre></div> </div> <p>This code will grab the latest, most recommended release of the Feature Server code from DevSeed&#8217;s feature server.</p> <h3>Future Directions</h3> <p>I&#8217;ve started an issue in the <a href="http://drupal.org/node/786916">Drush queue</a> to talk about some kind of repository scheme to help manage the download and file placement of code from individually preferred&nbsp;repositories.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/drush">drush</a></div><div class="field-item even"><a href="/category/terms/features">features</a></div><div class="field-item odd"><a href="/category/terms/features-servers">features-servers</a></div></div></div> Sat, 01 May 2010 07:14:15 +0000 Grayside 65 at http://grayside.org http://grayside.org/2010/05/drush-and-features-servers#comments