dusty
7/3/2008 3:00:00 AM
Here is a quick example program. Hope this gets you started.
#!/usr/bin/env ruby
require 'optparse'
options = {}
opts = OptionParser.new
opts.on("-W", "--weekday", "Print out the weekday") do |v|
options[:weekday] = true
end
opts.on("-H", "--hour TYPE", "Print out the hour in 24 or 12 hour
clock") do |v|
options[:hour] = v
end
opts.parse!
unless options[:weekday] || options[:hour]
puts opts
exit
end
if options[:weekday]
puts Time.now.strftime("%A")
exit
end
case options[:hour]
when "12"
puts Time.now.strftime("%I")
when "24"
puts Time.now.strftime("%H")
else
puts "You must send 12 or 24 as an argument to --hour"
end