<!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" dir="ltr" lang="en">
<head>
  <title>the all-thing</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="/static/style.css" type="text/css" />
  <link rel="alternate" type="application/rss+xml" title="the all-thing RSS feed" href="/index.rss" />
  <link rel="alternate" type="text/plain" title="the all-thing in plain text" href="/index.txt" />
  <script type="text/javascript" src="/static/mootools.js"></script>
  <script type="text/javascript" src="http://music.masanjin.net:9292/waxiest.js"></script>
</head>
<body>

<div id="main">
  <div id="header">
    <h1><a  href="/">the all-thing</a></h1>
    
      <p>Showing only posts labeled "trollop" (<a  href="/label/trollop.rss">rss</a>). <a  href="/index/">See all posts</a>.</p>
    
  </div>
  <div id="sidebar">
    <h3>Recent comments</h3>

    <ul class="sidebar-list">
    
    <li><b><a  href="/whisper-0.5#58174069c046a78e55f02ef81da81e74">Dominique Julia</a></b>
        <i><a  href="/whisper-0.5">Whisper 0.5 released</a></i>
           one week ago
    </li>
    
    <li><b><a  href="/ruby-ncurses-and-thread-blocking#8fa2a0f392d7c0562d630e4936407c11">William Morgan</a></b>
        <i><a  href="/ruby-ncurses-and-thread-blocking">Ruby, Ncurses and blocked threads</a></i>
           three months ago
    </li>
    
    <li><b><a  href="/git-wtf-bf06ab7-released#533654a7a229569e27a6d0afd716c444">William Morgan</a></b>
        <i><a  href="/git-wtf-bf06ab7-released">git wtf bf06ab7 released</a></i>
           three months ago
    </li>
    
    <li><b><a  href="/git-wtf-bf06ab7-released#b7b7a905477674eb6985b34a964a0dca">Joao Nelas</a></b>
        <i><a  href="/git-wtf-bf06ab7-released">git wtf bf06ab7 released</a></i>
           three months ago
    </li>
    
    <li><b><a  href="/ruby-ncurses-and-thread-blocking#b00001114360ac152f87d4ac2a6e0c5b">Ollivier Robert</a></b>
        <i><a  href="/ruby-ncurses-and-thread-blocking">Ruby, Ncurses and blocked threads</a></i>
           three months ago
    </li>
    
    </ul>

    <h3>Authors</h3>
    <ul class="sidebar-list">
    
      <li><a class="author" href="/by/William+Morgan/">William&nbsp;Morgan</a>&nbsp;(65) </li>
    
    </ul>

    <h3>Tags</h3>
    <ul class="sidebar-list">
    
      <li><a class="label" href="/label/releases/">releases</a>&nbsp;(15) </li>
    
      <li><a class="label" href="/label/whisper/">whisper</a>&nbsp;(13) </li>
    
      <li><a class="label" href="/label/git/">git</a>&nbsp;(9) </li>
    
      <li><a class="label" href="/label/stats/">stats</a>&nbsp;(8) </li>
    
      <li><a class="label" href="/label/trollop/">trollop</a>&nbsp;(6) </li>
    
      <li><a class="label" href="/label/ruby/">ruby</a>&nbsp;(6) </li>
    
      <li><a class="label" href="/label/sup/">sup</a>&nbsp;(6) </li>
    
      <li><a class="label" href="/label/git-wtf/">git-wtf</a>&nbsp;(4) </li>
    
      <li><a class="label" href="/label/vm/">vm</a>&nbsp;(4) </li>
    
      <li><a class="label" href="/label/mathml/">mathml</a>&nbsp;(3) </li>
    
      <li><a class="label" href="/label/continuations/">continuations</a>&nbsp;(3) </li>
    
      <li><a class="label" href="/label/ditz/">ditz</a>&nbsp;(3) </li>
    
      <li><a class="label" href="/label/proglang/">proglang</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/optimization/">optimization</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/benchmarks/">benchmarks</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/rubinius/">rubinius</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/inlining/">inlining</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/ubuntu/">ubuntu</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/fibers/">fibers</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/ritex/">ritex</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/ruby1.9/">ruby1.9</a>&nbsp;(2) </li>
    
      <li><a class="label" href="/label/ncurses/">ncurses</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/javascript/">javascript</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/media/">media</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/vim/">vim</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/classification/">classification</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/massachusetts/">massachusetts</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/greasemonkey/">greasemonkey</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/wine/">wine</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/readme/">readme</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/ancient-greek/">ancient-greek</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/web/">web</a>&nbsp;(1) </li>
    
      <li><a class="label" href="/label/current+events/">current&nbsp;events</a>&nbsp;(1) </li>
    
    </ul>

    <h3>Other formats</h3>
    <ul class="sidebar-list">
    <li><a href="/index.rss"><img src="/static/rss-badge.png"/></a></li>
    <li><a href="/index.txt">plain text version</a></li>
    </ul>

    <h3 class="waxiest.author.original">Who is this man?</h3>
    <h3 class="waxiest.author.beautiful" style="display:none">I must find out more about this beautiful creature</h3>
    <h3 class="waxiest.author.beautifulbig" style="display:none">I MUST FIND OUT MORE ABOUT THIS BEAUTIFUL CREATURE</h3>
    <h3 class="waxiest.author.originalbig" style="display:none">WHO IS THIS MAN?</h3>

    <script type="text/javascript">
      var w = waxiest();
      w.optimizeHTMLSection("author", ["original", "beautiful", "beautifulbig", "originalbig"]);
    </script>

    <a href="http://masanjin.net" onClick="w.goalReached('greeting')">William Morgan</a>
  </div>
  <div id="content">
    
  <h2><a  href="/trollop-1.15-released">Trollop 1.15 released</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="five months ago">September 30, 2009  6:59pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/trollop/">trollop</a></span> <span class='label'><a  href="/label/releases/">releases</a></span> </div>
  
  <p class='first'>I&#8217;ve just released <a href="http://trollop.rubyforge.org">Trollop</a> 1.15, which fixes an
irritating misfeature pointed out by Rafael Sevilla: when Trollop runs out of
characters when it&#8217;s generating short option names, e.g. when you have a lot of
options, it shouldn&#8217;t throw an exception and die. It should just continue peacefully.</p>
<p>Trollop&#8217;s <a href="http://stackoverflow.com/questions/897630/really-cheap-command-line-option-parsing-in-ruby/1012930#1012930">reign of domination</a> continues!</p>
  <div class="comment-link">
    
    <a  href="/trollop-1.15-released#comments">No comments</a>.
  </div>

  <h2><a  href="/trollop-1.13">Trollop 1.13 released</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="12 months ago">March 16, 2009  1:54pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/trollop/">trollop</a></span> <span class='label'><a  href="/label/releases/">releases</a></span> </div>
  
  <p class='first'>I&#8217;ve released Trollop 1.13. This is a minor bugfix release. Arguments
given with =&#8217;s and with spaces in the values are now parsed correctly.
(E.g. <code>--name="your mom"</code>.)</p>
<p>Get it with a quick <code>gem install trollop</code>.</p>
  <div class="comment-link">
    
    <a  href="/trollop-1.13#comments">Three comments by <b>Trisha Leavitt</b>, <b>William Morgan</b>, and one other</a>.
  </div>

  <h2><a  href="/old27">Trollop 1.11 released</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="13 months ago">January 29, 2009 10:03pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/trollop/">trollop</a></span> <span class='label'><a  href="/label/releases/">releases</a></span> </div>
  
  <p class='first'>Trollop 1.11 has been released. This is a minor release with only one new feature: when an option <code>&lt;opt&gt;</code> is actually given on the commandline, a new key <code>&lt;opt&gt;_given</code> is inserted into the return hash (in addition to <code>&lt;opt&gt;</code> being set to the actual argument(s) specified).</p>
<p>This allows you to detect which options were actually specified on the commandline. This is necessary for situations where you want one option to override or somehow influence other options. For example, configure&#8217;s <code>--exec-prefix</code> and <code>--bindir</code> flags: if <code>--exec-prefix</code> is specified, you want to override the default value for <code>--bindir</code>, unless that&#8217;s also given. If neither are given, you want to use the default values.</p>
<p>This should be a backwards-compatible release, except for namespace issues, if you actually had options called <code>&lt;something&gt;-given</code>.</p>
  <div class="comment-link">
    
    <a  href="/old27#comments">Four comments by <b>Martin Elzen</b> and <b>William Morgan</b></a>.
  </div>

  <h2><a  href="/old7">Trollop 1.10 released</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="16 months ago">October 21, 2008  9:33pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/releases/">releases</a></span> <span class='label'><a  href="/label/trollop/">trollop</a></span> </div>
  
  <p class='first'>I released a new version of <a href="http://trollop.rubyforge.org/">Trollop</a> with a
couple minor but cool updates.</p>
<p>The best part is the new <code>:io</code> argument type, which uses <code>open-uri</code> to handle
filenames and URIs on the commandline. So you can do something like this:</p>
<p><code><pre class="ruby"><span class="ident">require</span> <span class="punct">'</span><span class="string">trollop</span><span class="punct">'</span>
<span class="ident">opts</span> <span class="punct">=</span> <span class="constant">Trollop</span><span class="punct">::</span><span class="ident">options</span> <span class="keyword">do</span>
  <span class="ident">opt</span> <span class="symbol">:source</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">Source file (or URI) to print</span><span class="punct">&quot;,</span>
      <span class="symbol">:type</span> <span class="punct">=&gt;</span> <span class="symbol">:io</span><span class="punct">,</span>
      <span class="symbol">:required</span> <span class="punct">=&gt;</span> <span class="constant">true</span>
<span class="keyword">end</span>
<span class="ident">opts</span><span class="punct">[</span><span class="symbol">:source</span><span class="punct">].</span><span class="ident">each</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">l</span><span class="punct">|</span> <span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">&gt; <span class="expr">#{l.chomp}</span></span><span class="punct">&quot;</span> <span class="punct">}</span></pre></code></p>
<p>Also, when trying to detect the terminal size, Trollop now tries to <code>`stty
size`</code> before loading curses. This gives better results when running under
screen (for some reason curses clears the terminal when initializing under
screen).</p>
<p>I&#8217;ve also cleaned up the documentation quite a bit, expanding the examples on
the <a href="http://trollop.rubyforge.org/">main page</a>, fixing up the RDoc comments, and
generating the <a href="http://trollop.rubyforge.org/trollop/">RDoc documentation</a> with
a modern RDoc, so that things like constants actually get documented.</p>
<p>If you&#8217;re still using OptParse, you should really give Trollop a try. I
guarantee you&#8217;ll write much fewer lines of argument parsing code, and you&#8217;ll
get all sorts of nifty features like help page terminal size detection.</p>
  <div class="comment-link">
    
    <a  href="/old7#comments">Four comments by <b>Quatauta</b>, <b>quatauta</b>, and one other</a>.
  </div>

  <h2><a  href="/old32">Trollop news</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="19 months ago">July 30, 2008  6:58pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/trollop/">trollop</a></span> </div>
  
  <p class='first'>Looks like there was a <a href="http://www.rubyinside.com/trollop-command-line-option-parser-for-ruby-944.html">Ruby Inside article featuring Trollop</a> a few weeks ago. Partially as a result of this, I have at least two other people contributing patches. For a project that&#8217;s been around for a few years and basically had no one but me use it, that&#8217;s a nice change of pace.</p>
<p>I&#8217;ve also moved it over from <span class="caps">SVN</span> to git (hosted on <a href="http://gitorious.org/projects/trollop">Gitorious</a>), which probably will help some.</p>
  <div class="comment-link">
    
    <a  href="/old32#comments">Three comments by <b>William</b>, <b>Peter Cooper</b>, and one other</a>.
  </div>

  <h2><a  href="/old24">Trollop 1.8.1 released</a></h2>
  <div class="byline">
    <a  href="/by/William+Morgan/">William Morgan</a>,
    <span title="20 months ago">June 24, 2008  7:07pm</span>
  </div>
  
    <div class="labels"><span class='label'><a  href="/label/trollop/">trollop</a></span> <span class='label'><a  href="/label/releases/">releases</a></span> </div>
  
  <p class='first'><a href="http://trollop.rubyforge.org/">Trollop 1.8.1</a> is out. This is a minor bugfix
release, but 1.8, released a few weeks ago but not really advertised, adds new
functionality, so I&#8217;m describing that here.</p>
<p>The new functionality is subcommand support, as seen in things like <code>git</code> and
<code>svn</code>. This feature is actually trivial to use / implement: you give Trollop a
list of stopwords. When it sees one, it stops parsing. The end. That&#8217;s all you
need.</p>
<p>Here&#8217;s how you use it:</p>
<ul>
	<li>Call <code>Trollop::options</code> with your global option specs. Pass it the list of subcommands as the stopwords. It will parse <code>ARGV</code> and stop on the subcommand.</li>
	<li>Parse the next word in <span class="caps">ARGV</span> as the subcommand, however you wish. <code>ARGV.shift</code> is the traditional choice.</li>
	<li>Call <code>Trollop::options</code> again with whatever command-specific options you want.</li>
</ul>
<p>And that&#8217;s it. Simple eh?</p>
<p>It continually amazes me how hard other people make option parsing. I think
it&#8217;s a holdover from their days of using C or Java. Take a look at synopsis for
<a href="http://docs.huihoo.com/rdoc/ruby/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html">optparse</a>
— it&#8217;s a ridiculous amount of work for something simple. Or better yet, look at
the synopsis for <a href="http://cmdparse.rubyforge.org/tutorial.html">CmdParse</a>. Having
to make a class for each command is a clunky Java-ism. I&#8217;m sorry, but it&#8217;s
true. Subclassing is the one option for specializing code in Java; in Ruby we
can be far more sophisticated. Take a look at
<a href="http://ditz.rubyforge.org/">Ditz&#8217;s</a>
<a href="http://gitorious.org/projects/ditz/repos/mainline/blobs/master/lib/operator.rb">operator.rb</a>
for an example of a subcommand <span class="caps">DSL</span>.</p>
  <div class="comment-link">
    
    <a  href="/old24#comments">Two comments by <b>William</b> and <b>Brendan</b></a>.
  </div>




  </div>

  <div id="footer" style="margin: 0px;">
    Served up by <a href="http://masanjin.net/whisper/">Whisper</a>. Yes!
  </div>
</div>
</body>
</html>
