We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

robh on 04/26/08


Tagged

textmate ruby cli options parser


Versions (?)


test snipplr snippet


Published in: Other 


  1. op = OptionParser.new do |opts|
  2. opts.banner = "Usage: #{$0} [options] directory."
  3. opts.on('-v', '--verbose', 'Run verbosely') do |v|
  4. options[:verbose] = v
  5. end
  6. opts.on('-o [TYPE]', '--output [TYPE]', "Output as: #{output_types.join(', ')}.") do |o|
  7. raise Exception.new("Invalid output type: #{o}") unless output_types.include?(o)
  8. options[:output] = o.to_sym
  9. end
  10. opts.on('-m [MIN_SIZE]', '--minimum-size [MIN_SIZE]', 'Minimum word size to capture.') do |m|
  11. options[:min_word_size] = m.to_i
  12. end
  13. opts.on('-p', '--preserve-case', 'Preserves the case of words.') do |p|
  14. options[:preserve_case] = p
  15. end
  16. opts.on_tail("-h", "--help", "Show this message") do
  17. puts opts
  18. exit
  19. end
  20. end
  21.  

Report this snippet 

You need to login to post a comment.