title: OptionParser with subcommands
body: <p>I'm trying to create a command line program with sub-commands using OptionParser. I'm following "<a href="https://gist.github.com/rkumar/445735" rel="nofollow">ruby's OptionParser to get subcommands</a>".</p>
  
  <p>The problem is that it does not allow for a use case like this:</p>
  
  <pre><code>ruby main.rb --version 
  #=&gt; main.rb in `&lt;main&gt;': undefined method `order!' for nil:NilClass (NoMethodError)
  </code></pre>
  
  <p>But it does allow for this:</p>
  
  <pre><code>ruby main.rb foo --options
  ruby main.rb --options foo
  ruby main.rb --options foo --options
  </code></pre>
  
  <p>How would I be properly handle command line arguments, in the case that no subcommand is given.</p>
  
  <p>My example code is:</p>
  
  <pre><code>global = OptionParser.new do |opts|
    opts.banner = "Usage: opt.rb [options] [subcommand [options]]"
    opts.on("-v", "--version", "Print the version") do |v|
      options[:version] = v
    end
    opts.separator ""
    opts.separator subtext
  end
  </code></pre>