<!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>
    
  </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="/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>

<h4>Discussion</h4>
<a name="comments"></a>

<ul class="comment-tree">

  <li>
  
  <a name="old-comment-7"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author">quatauta</td>
          <td class="comment-date" title="16 months ago"><a href="#old-comment-7">October 29, 2008  4:39am</a></td>
    </tr></table>
    <p class='first'>Hi,</p>
<p>started using Trollop yesterday, I really like it.</p>
<p>I realized one difference to Optparse in the parser and I don&#8217;t know if it
is intentional: It seems impossible to give a short option and its parameter as
one argument.</p>
<p>Example:</p>
<p><code><pre class="ruby"><span class="ident">require</span> <span class="punct">&quot;</span><span class="string">trollop</span><span class="punct">&quot;</span>
<span class="ident">require</span> <span class="punct">&quot;</span><span class="string">pp</span><span class="punct">&quot;</span>

<span class="keyword">def </span><span class="method">a</span><span class="punct">(*</span><span class="ident">args</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="punct">(</span><span class="ident">args</span><span class="punct">)</span> <span class="keyword">do</span>
    <span class="ident">opt</span> <span class="symbol">:aaa</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">Test</span><span class="punct">&quot;,</span> <span class="symbol">:type</span> <span class="punct">=&gt;</span> <span class="symbol">:string</span>
  <span class="keyword">end</span>
  <span class="ident">pp</span> <span class="ident">opts</span>
<span class="keyword">end</span>

<span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">:: Two args</span><span class="punct">&quot;</span>
<span class="ident">a</span><span class="punct">(&quot;</span><span class="string">-a</span><span class="punct">&quot;,</span> <span class="punct">&quot;</span><span class="string">1</span><span class="punct">&quot;)</span>
<span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">:: Combined in one arg:</span><span class="punct">&quot;</span>
<span class="ident">a</span><span class="punct">(&quot;</span><span class="string">-a1</span><span class="punct">&quot;)</span></pre></code></p>
<p>Calling this:</p>
<p><code><pre class="ruby"><span class="punct">::</span> <span class="constant">Two</span> <span class="ident">args</span><span class="punct">:</span>
<span class="punct">{</span><span class="symbol">:aaa=</span><span class="punct">&gt;&quot;</span><span class="string">1</span><span class="punct">&quot;,</span> <span class="symbol">:help=</span><span class="punct">&gt;</span><span class="constant">false</span><span class="punct">}</span>
<span class="punct">::</span> <span class="constant">Combined</span> <span class="keyword">in</span> <span class="ident">one</span> <span class="ident">arg</span><span class="punct">:</span>
<span class="constant">Error</span><span class="punct">:</span> <span class="ident">unknown</span> <span class="ident">argument</span> <span class="punct">&quot;</span><span class="string">-1</span><span class="punct">&quot;.</span>
<span class="ident">Try</span> <span class="punct">--</span><span class="ident">help</span> <span class="keyword">for</span> <span class="ident">help</span><span class="punct">.</span></pre></code></p>
    <div class="reply-to-outer">
      <div class="reply-to-header"><a href="#" class="reply-to-link">reply</a></div>
      <div class="reply-to-box" id="reply-to-old7-old-comment-7" >
        <span class="comment-instructions">To reply, enter your email address. A copy of the comment will be sent to you via email.</span>
        <form id='comment-form-old7-old-comment-7' action='/comment/old7' method='post' class='comment-form'>
          <input type='text' name='email' id='textfield-email'/>
          <input type='submit' value='email me' id='submit-email me'/>
        <input type='hidden' name='comment-id' value='old-comment-7'/>
  <span class="form-result" id="form-result-old7-old-comment-7"><!-- spanna --></span>
</form>

      </div>
    </div>
  </div>

  </li><li>
  
  <a name="old-comment-6"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author"><a href="http://masanjin.net/">William</a></td>
          <td class="comment-date" title="16 months ago"><a href="#old-comment-6">October 29, 2008 11:16am</a></td>
    </tr></table>
    <div class='comment-quote'>
<p>I realized one difference to Optparse in the parser and I don&#8217;t know if it is
intentional: It seems impossible to give a short option and its parameter as
one argument.</p>
</div><p class='first'>Weird, I didn&#8217;t know Optparse supported something like that. I&#8217;ve never seen
that syntax before.</p>
<p>Supporting it would conflict with Trollop&#8217;s short option bundling, e.g. Trollop
allows &#8220;-p -e&#8221; to be written as &#8220;-pe&#8221;. Since that&#8217;s a standard feature (e.g.
ruby itself!) I&#8217;m not eager to interfere with it.</p>
    <div class="reply-to-outer">
      <div class="reply-to-header"><a href="#" class="reply-to-link">reply</a></div>
      <div class="reply-to-box" id="reply-to-old7-old-comment-6" >
        <span class="comment-instructions">To reply, enter your email address. A copy of the comment will be sent to you via email.</span>
        <form id='comment-form-old7-old-comment-6' action='/comment/old7' method='post' class='comment-form'>
          <input type='text' name='email' id='textfield-email'/>
          <input type='submit' value='email me' id='submit-email me'/>
        <input type='hidden' name='comment-id' value='old-comment-6'/>
  <span class="form-result" id="form-result-old7-old-comment-6"><!-- spanna --></span>
</form>

      </div>
    </div>
  </div>

  </li><li>
  
  <a name="old-comment-5"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author">Quatauta</td>
          <td class="comment-date" title="16 months ago"><a href="#old-comment-5">October 29, 2008 11:27am</a></td>
    </tr></table>
    <p class='first'>OK, thanks.</p>
<p>As far as I know, Optparse (and <span class="caps">GNU</span> getopt) allows &#8220;-a -b -c 12&#8221; (where -a and
-b are flags, only -c gets/need a parameter) to be given as &#8220;-abc12&#8221;, but not
&#8220;-c12ab&#8221;. Only the last option can take a parameter.</p>
    <div class="reply-to-outer">
      <div class="reply-to-header"><a href="#" class="reply-to-link">reply</a></div>
      <div class="reply-to-box" id="reply-to-old7-old-comment-5" >
        <span class="comment-instructions">To reply, enter your email address. A copy of the comment will be sent to you via email.</span>
        <form id='comment-form-old7-old-comment-5' action='/comment/old7' method='post' class='comment-form'>
          <input type='text' name='email' id='textfield-email'/>
          <input type='submit' value='email me' id='submit-email me'/>
        <input type='hidden' name='comment-id' value='old-comment-5'/>
  <span class="form-result" id="form-result-old7-old-comment-5"><!-- spanna --></span>
</form>

      </div>
    </div>
  </div>

  </li><li>
  
  <a name="old-comment-4"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author"><a href="http://masanjin.net/">William</a></td>
          <td class="comment-date" title="16 months ago"><a href="#old-comment-4">October 29, 2008 11:42am</a></td>
    </tr></table>
    <div class='comment-quote'>
<p class='first'>As far as I know, Optparse (and <span class="caps">GNU</span> getopt) allows &#8220;-a -b -c 12&#8221; (where -a and
-b are flags, only -c gets/need a parameter) to be given as &#8220;-abc12&#8221;, but not
&#8220;-c12ab&#8221;. Only the last option can take a parameter.</p>
</div><p>Ah, I see. Yes, I would like to support that. Shouldn&#8217;t be too hard of a patch.</p>
<p>Thanks!</p>
    <div class="reply-to-outer">
      <div class="reply-to-header"><a href="#" class="reply-to-link">reply</a></div>
      <div class="reply-to-box" id="reply-to-old7-old-comment-4" >
        <span class="comment-instructions">To reply, enter your email address. A copy of the comment will be sent to you via email.</span>
        <form id='comment-form-old7-old-comment-4' action='/comment/old7' method='post' class='comment-form'>
          <input type='text' name='email' id='textfield-email'/>
          <input type='submit' value='email me' id='submit-email me'/>
        <input type='hidden' name='comment-id' value='old-comment-4'/>
  <span class="form-result" id="form-result-old7-old-comment-4"><!-- spanna --></span>
</form>

      </div>
    </div>
  </div>

  </li>
  
</ul>

<p class="comment-instructions">To leave a new comment, enter your email
address. A copy of the article will be sent to you via email.</p>
<form id='comment-form-old7' action='/comment/old7' method='post' class='comment-form'>
  <input type='text' name='email' id='textfield-email'/>
  <input type='submit' value='email me' id='submit-email me'/>
  <span class="form-result" id="form-result-old7"><!-- spanna --></span>
</form>


<script type="text/javascript">
/* <![CDATA[ */
$$('.comment-form').addEvent('submit', function(e) {
  e.stop();
  var el = this.getElement('.form-result');
  var result = el.empty().addClass('ajax-loading');
  this.set('send', {
    method: 'post',
    onComplete: function(response) { 
      result.removeClass('ajax-loading');
      result.set('html', response);
    },
  });
  this.send();
});
/* ]]> */
</script>


<script type="text/javascript">
/* <![CDATA[ */
$$('.reply-to-link').each(function(link, i) {
  var box = link.getParent().getParent().getElement('.reply-to-box');
  var oldHeight = box.getStyle("height");
  box.setStyle("height", 0);
  box.setStyle("opacity", 0);
  link.addEvent('click', function(e) {
    e.stop();
    box.setStyle("opacity", 1);
    box.setStyle("height", oldHeight);
    box.getElement("input").focus();
  });
});
/* ]]> */
</script>

  </div>

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