diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-25 23:10:36 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-25 23:10:36 +0000 |
commit | c26e86fd1bb18d3842c95f61e2cfcf15072d76f4 (patch) | |
tree | 96db636f6bed5ce3bd4859bd0f8c15c375d8a413 /sample | |
parent | 7e827e66944e4a04c64eb72dde794e81e9d0d1b0 (diff) | |
download | ruby-c26e86fd1bb18d3842c95f61e2cfcf15072d76f4.tar.gz |
synchronized with date2 3.6.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r-- | sample/cal.rb | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/sample/cal.rb b/sample/cal.rb index fa20352f71..197cdfe3a6 100644 --- a/sample/cal.rb +++ b/sample/cal.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby # cal.rb: Written by Tadayoshi Funaba 1998-2004 -# $Id: cal.rb,v 2.7 2004-01-10 23:52:51+09 tadf Exp $ +# $Id: cal.rb,v 2.8 2004-09-25 12:50:10+09 tadf Exp $ require 'date' @@ -121,17 +121,36 @@ end if __FILE__ == $0 - require 'getopts' + require 'getoptlong' def usage warn 'usage: cal [-c iso3166] [-jmty] [[month] year]' exit 1 end - usage unless getopts('jmty', "c:#{Cal::DEFAULT_START}") + cal = Cal.new + + begin + GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT], + ['-j', GetoptLong::NO_ARGUMENT], + ['-m', GetoptLong::NO_ARGUMENT], + ['-t', GetoptLong::NO_ARGUMENT], + ['-y', GetoptLong::NO_ARGUMENT]). + each do |opt, arg| + case opt + when '-c'; cal.opt_c(arg) || raise + when '-j'; cal.opt_j(true) + when '-m'; cal.opt_m(true) + when '-t'; cal.opt_t(true) + when '-y'; cal.opt_y(true) + end + end + rescue + usage + end y, m = ARGV.values_at(1, 0).compact.collect{|x| x.to_i} - $OPT_y ||= (y and not m) + cal.opt_y(true) if y and not m to = Date.today y ||= to.year @@ -139,15 +158,6 @@ if __FILE__ == $0 usage unless m >= 1 and m <= 12 usage unless y >= -4712 - usage if Cal::START[$OPT_c].nil? - - cal = Cal.new - - cal.opt_j($OPT_j) - cal.opt_m($OPT_m) - cal.opt_t($OPT_t) - cal.opt_y($OPT_y) - cal.opt_c($OPT_c) print cal.print(y, m) |