Posted By

mikegreen on 05/20/08


Tagged

ruby commandline cli


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

sergeizen
georg
webstic


Ruby Command Line Option Parser


 / Published in: Ruby
 

Simple command line option parser snippet

  1. require 'optparse'
  2.  
  3. app = Hash.new
  4.  
  5. options = OptionParser.new do |opts|
  6. opts.on("-o", "--option [ARG]", "Option description") do |opt|
  7. app['option'] = opt
  8. end
  9. end
  10.  
  11. begin
  12. options.parse!(ARGV)
  13. rescue OptionParser::ParseError => e
  14. puts e
  15. end

Report this snippet  

You need to login to post a comment.