Last active
May 31, 2016 06:04
-
-
Save danielribeiro/98e36f7d1ae3e19d87e5729fc98c7297 to your computer and use it in GitHub Desktop.
optparsing.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'pp' | |
options = {} | |
parser = OptionParser.new do |opts| | |
opts.banner = "Usage: example.rb [options]" | |
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| | |
options[:verbose] = v | |
end | |
opts.on("-i", "--integer=int", Integer, "gives integer") do |v| | |
options[:integer] = v | |
end | |
end | |
pr = proc do |event, file, line, id, binding, classname| | |
puts("TraceALLThings (%8s) %s:%-2d %s#%s\n" % [event, file, line, classname, id]) | |
end | |
# set_trace_func(pr) | |
parser.parse! | |
puts parser | |
p options | |
p ARGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
look into: https://rosettacode.org/wiki/Parse_command-line_arguments#Ruby_with_.27optparse.27