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

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

<ul class="comment-tree">

  <li>
  
  <a name="77bed1377c64ed1b8112bf3e4c1c96cc"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author">Martin Elzen</td>
          <td class="comment-date" title="12 months ago"><a href="#77bed1377c64ed1b8112bf3e4c1c96cc">March  8, 2009  3:36pm</a></td>
    </tr></table>
    
    <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-old27-77bed1377c64ed1b8112bf3e4c1c96cc" >
        <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-old27-77bed1377c64ed1b8112bf3e4c1c96cc' action='/comment/old27' 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='77bed1377c64ed1b8112bf3e4c1c96cc'/>
  <span class="form-result" id="form-result-old27-77bed1377c64ed1b8112bf3e4c1c96cc"><!-- spanna --></span>
</form>

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

  <ul><li>
  
  <a name="8e985c5017e08235e596692d32a0afef"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author"><a href="http://masanjin.net/">William Morgan</a></td>
          <td class="comment-date" title="12 months ago"><a href="#8e985c5017e08235e596692d32a0afef">March 10, 2009  3:24pm</a></td>
    </tr></table>
    <p>Did you mean to say something? Your email was blank.</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-old27-8e985c5017e08235e596692d32a0afef" >
        <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-old27-8e985c5017e08235e596692d32a0afef' action='/comment/old27' 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='8e985c5017e08235e596692d32a0afef'/>
  <span class="form-result" id="form-result-old27-8e985c5017e08235e596692d32a0afef"><!-- spanna --></span>
</form>

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

  </li></ul></li><li>
  
  <a name="6a6ed0f2efb6638bd48dd651a2d937a3"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author">Martin Elzen</td>
          <td class="comment-date" title="12 months ago"><a href="#6a6ed0f2efb6638bd48dd651a2d937a3">March 12, 2009 11:33pm</a></td>
    </tr></table>
    <p class='first'>Hi, yes I <strong>did</strong> write an email, guess Firefox &#8216;ate&#8217; it, so I&#8217;m using Safari for this&#8230;.  I don&#8217;t remember exactly what I wrote, but I&#8217;ll do my best to remember.
First issue I had after running that &#8220;gem install trollop&#8221; (or something like) line in a Dos prompt shell on Vista is that entering &#8216;ri Trollop&#8217; returns &#8216;Nothing known about Trollop&#8217;&#8230;  Even though the gem install program did not report any problems&#8230;  So I&#8217;m glad the docs are available online.
2nd issue: the line &quot; require &#8216;trollop&#8217; &quot; in a Ruby script resulted in an error, don&#8217;t remember which now (this was solved by manually copying trollop.rb to c:\Ruby\lib\1.8 (or something close to that) )
3rd issue: could you make a correct example on how to call the parse method by hand? I tried the following:require &#8216;trollop&#8217;
parser = Trollop::Parser opts = parser.parse(<span class="caps">ARGV</span>) do  opt :monkey, &#8220;Use monkey mode&#8221;                     # a flag &#8212;monkey, defaulting to false  opt :goat, &#8220;Use goat mode&#8221;, :default =&gt; true       # a flag &#8212;goat, defaulting to true  opt :num_limbs, &#8220;Number of limbs&#8221;, :default =&gt; 4   # an integer &#8212;num-limbs &lt;i&gt;, defaulting to 4  opt :num_thumbs, &#8220;Number of thumbs&#8221;, :type =&gt; :int # an integer &#8212;num-thumbs &lt;i&gt;, defaulting to nilend
p opts # returns a hash: { :monkey =&gt; false, :goat =&gt; true, :num_limbs =&gt; 4, :num_thumbs =&gt; nil }
but Ruby (most recent 1.8.6 RC2 1 click installer version) then says: &#8216;undefined method &#8217;parse&#8217; for Trollop::Parser::Class&#8217; and I&#8217;m not seeing the mistake I&#8217;m making&#8230;
4th and last: is there a way to get Trollop to simply return the options it doesn&#8217;t recognize?  I certainly don&#8217;t want an exception to be raised for that,since I&#8217;ve been taught that exceptions should only be used for &#8216;exceptional circumstances&#8217;, and typo&#8217;s don&#8217;t seem that exceptional for me (this issue is a bit moot for me now, since I began to roll my own after neither getlongopts, nor optparse nor Trollop seemed to fit my bill close enough,but might be handy for others who also want their option parser to stay out of the way&#8230;)</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-old27-6a6ed0f2efb6638bd48dd651a2d937a3" >
        <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-old27-6a6ed0f2efb6638bd48dd651a2d937a3' action='/comment/old27' 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='6a6ed0f2efb6638bd48dd651a2d937a3'/>
  <span class="form-result" id="form-result-old27-6a6ed0f2efb6638bd48dd651a2d937a3"><!-- spanna --></span>
</form>

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

  <ul><li>
  
  <a name="4d725d908c8002ddcc1929597f3cb048"></a>
  <div class="comment-body">
    <table class="comment-byline">
      <tr><td class="comment-author"><a href="http://masanjin.net/">William Morgan</a></td>
          <td class="comment-date" title="12 months ago"><a href="#4d725d908c8002ddcc1929597f3cb048">March 13, 2009  9:00pm</a></td>
    </tr></table>
    <div class='comment-quote' title="Reformatted excerpts from Martin Elzen's message of 2009-03-13:">
<p class='first'>First issue I had after running that &#8220;gem install trollop&#8221; (or
something like) line in a Dos prompt shell on Vista is that entering
&#8216;ri Trollop&#8217; returns &#8216;Nothing known about Trollop&#8217;&#8230;  Even though the
gem install program did not report any problems&#8230;  So I&#8217;m glad the
docs are available online.  2nd issue: the line &quot; require &#8216;trollop&#8217; &quot;
in a Ruby script resulted in an error, don&#8217;t remember which now (this
was solved by manually copying trollop.rb to c:\Ruby\lib\1.8 (or
something close to that) )</p>
</div><p>These two sound like gem installation issues.</p><div class='comment-quote'>
<p class='first'>3rd issue: could you make a correct example on how to call the parse method by
hand? I tried the following:
<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">parser</span> <span class="punct">=</span> <span class="constant">Trollop</span><span class="punct">::</span><span class="constant">Parser</span>
<span class="ident">opts</span> <span class="punct">=</span> <span class="ident">parser</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">(</span><span class="constant">ARGV</span><span class="punct">)</span> <span class="keyword">do</span>
<span class="ident">opt</span> <span class="symbol">:monkey</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">Use monkey mode</span><span class="punct">&quot;</span>                     <span class="comment"># a flag --monkey, defaulting to false</span></pre></code>
but Ruby (most recent 1.8.6 RC2 1 click installer version) then says:
&#8216;undefined method &#8217;parse&#8217; for Trollop::Parser::Class&#8217; and I&#8217;m not seeing the
mistake I&#8217;m making&#8230;</p>
</div><p>You need something like:</p>
<p><code><pre class="ruby"><span class="ident">parser</span> <span class="punct">=</span> <span class="constant">Trollop</span><span class="punct">::</span><span class="constant">Parser</span><span class="punct">.</span><span class="ident">new</span> <span class="keyword">do</span>
  <span class="ident">opt</span> <span class="symbol">:monkey</span><span class="punct">,</span> <span class="punct">&quot;</span><span class="string">User monkey mode</span><span class="punct">&quot;</span>
<span class="keyword">end</span>

<span class="ident">opts</span> <span class="punct">=</span> <span class="ident">parser</span><span class="punct">.</span><span class="ident">parse</span> <span class="constant">ARGV</span></pre></code></p><div class='comment-quote'>
<p class='first'>4th and last: is there a way to get Trollop to simply return the
options it doesn&#8217;t recognize?  I certainly don&#8217;t want an exception to
be raised for that,since I&#8217;ve been taught that exceptions should only
be used for &#8216;exceptional circumstances&#8217;, and typo&#8217;s don&#8217;t seem that
exceptional for me</p>
</div><p>No. You could do something with <code>stop_on_unknown</code>, maybe, but it would
be ugly. Exceptions are the right approach here.</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-old27-4d725d908c8002ddcc1929597f3cb048" >
        <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-old27-4d725d908c8002ddcc1929597f3cb048' action='/comment/old27' 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='4d725d908c8002ddcc1929597f3cb048'/>
  <span class="form-result" id="form-result-old27-4d725d908c8002ddcc1929597f3cb048"><!-- spanna --></span>
</form>

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

  </li></ul></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-old27' action='/comment/old27' 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-old27"><!-- 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>
