On May 16, 2006, at 8:22 AM, Paul D. Kraus wrote:

> no I want to call my script like such ...
> ./myscript.rb -d 2006-08-06

Have you tried CommandLine?


>
> I then want to validate what is being set in -d.
> Here is the code I have that works but it just seems excessive to  
> have to
> loop through the options...
>
> def getopts
>  opts = GetoptLong.new([ '-d', '--date',  
> GetoptLong::REQUIRED_ARGUMENT])
>  opts.each do |opt,arg|
>    if opt =~ /-d|--date/ && arg =~ /(\d{4})-(\d{2})-(\d{2})/
>        date = arg.gsub('-','')
>        return date
>    else
>      puts "Date needs to be set to YYYY-MM-DD using -d or --date"
>      exit
>    end
>  end
> end
>
> I thought I would just be able to do...
> if opt['-d'] =~ <rxhere> || opt['--date'] =~ <rxhere>
>  <code here>
> end
>
>
> Thanks.
> Paul Kraus

Jim Freeze