Montag, 29. Dezember 2008

get options with getoptlong

install:

~# gem install getopt
Successfully installed getopt-1.3.7
1 gem installed
Installing ri documentation for getopt-1.3.7...
Installing RDoc documentation for getopt-1.3.7...

need: require 'getoptlong'



#!/usr/bin/ruby

require 'getoptlong'

opts = GetoptLong.new(
[ "--test", "-t", GetoptLong::REQUIRED_ARGUMENT ],
[ "--blub", "-b", GetoptLong::OPTIONAL_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
[ "--usage", "-u", GetoptLong::NO_ARGUMENT ],
[ "--version", "-v", GetoptLong::NO_ARGUMENT ]
)

opts.each do |opt, arg|
case opt
when "--test"
puts "we must extract :#{arg}:"
when "--blub"
puts "blub blub : #{arg} :"
when "--help"
puts "help yourself"
when "--usage"
puts "getoiptlong.rb"
puts " -t, -b, -h, -u , -v"
when "--version"
puts "version 0.01"
else
puts "upsala"
end
end

Keine Kommentare:

Kommentar veröffentlichen