Created
September 1, 2011 23:22
-
-
Save dgrijalva/1187559 to your computer and use it in GitHub Desktop.
Option Parsing in 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 'ostruct' | |
# OPTIONS PARSING | |
options = OpenStruct.new | |
parser = OptionParser.new do |opts| | |
opts.banner = "Usage: #{File.basename(__FILE__)} [options] [files]" | |
opts.on('-v', '--verbose', 'Verbose') do | |
# TODO: add some verbosity | |
options.verbose = true | |
end | |
opts.on('-f', '--file="file"', "The file to use") do |file| | |
options.filename = filename | |
end | |
opts.on('-h', '--help', 'Show this message') do | |
puts opts | |
exit | |
end | |
end | |
parser.parse!(ARGV) | |
# Anything unparsed remains in ARGV | |
# in the above example files = ARGV after parsing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment