Ruby Command Line Option Parser


/ Published in: Ruby
Save to your folder(s)

Simple command line option parser snippet


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.