Created
December 28, 2015 16:12
-
-
Save ejimz/3bfef8776061ce5ce396 to your computer and use it in GitHub Desktop.
Option parser ruby example
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' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: example.rb [options]" | |
#string as argument | |
opts.on("-u", "--url [URL]", String, "Remote url") do |url| | |
options[:url] = url | |
end | |
#Boolean as argument | |
opts.on("-v", "--[no-]verbose", "Run verbosely") do |verbose| | |
options[:verbose] = verbose | |
end | |
opts.on("-h", "--help", "Show this help") do |v| | |
puts opts | |
end | |
end.parse! | |
p options | |
p ARGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment