Skip to content

Instantly share code, notes, and snippets.

@ejimz
Created December 28, 2015 16:12
Show Gist options
  • Save ejimz/3bfef8776061ce5ce396 to your computer and use it in GitHub Desktop.
Save ejimz/3bfef8776061ce5ce396 to your computer and use it in GitHub Desktop.
Option parser ruby example
#!/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