mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/optparse.rb: get rid of warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bec6d3b1b9
commit
564c80b10a
6 changed files with 34 additions and 14 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Wed May 21 13:26:08 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* lib/optparse.rb: get rid of warnings.
|
||||||
|
|
||||||
Tue May 20 18:59:54 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue May 20 18:59:54 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_thread_save_context): prohibit rb_gc_force_recycle()
|
* eval.c (rb_thread_save_context): prohibit rb_gc_force_recycle()
|
||||||
|
|
|
@ -844,8 +844,7 @@ Default options, which never appear in option summary.
|
||||||
--- OptionParser#to_s
|
--- OptionParser#to_s
|
||||||
Returns option summary string.
|
Returns option summary string.
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
def to_str; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
|
def to_s; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
|
||||||
alias to_s to_str
|
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
--- OptionParser#to_a
|
--- OptionParser#to_a
|
||||||
|
@ -1325,9 +1324,9 @@ Default options, which never appear in option summary.
|
||||||
: Object
|
: Object
|
||||||
any string, and no conversion. this is fall-back.
|
any string, and no conversion. this is fall-back.
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
accept(Object) {|s|s or s.nil?}
|
accept(Object) {|s,|s or s.nil?}
|
||||||
|
|
||||||
accept(NilClass) {|s|s}
|
accept(NilClass) {|s,|s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: String
|
: String
|
||||||
|
@ -1346,7 +1345,7 @@ Default options, which never appear in option summary.
|
||||||
hex = 'x[\da-f]+(?:_[\da-f]+)*'
|
hex = 'x[\da-f]+(?:_[\da-f]+)*'
|
||||||
octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})"
|
octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})"
|
||||||
integer = "#{octal}|#{decimal}"
|
integer = "#{octal}|#{decimal}"
|
||||||
accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s| Integer(s) if s}
|
accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s,| Integer(s) if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: Float
|
: Float
|
||||||
|
@ -1354,21 +1353,21 @@ Default options, which never appear in option summary.
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
|
float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
|
||||||
floatpat = %r"\A[-+]?#{float}"io
|
floatpat = %r"\A[-+]?#{float}"io
|
||||||
accept(Float, floatpat) {|s| s.to_f if s}
|
accept(Float, floatpat) {|s,| s.to_f if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: Numeric
|
: Numeric
|
||||||
Generic numeric format, and converts to (({Integer})) for integer
|
Generic numeric format, and converts to (({Integer})) for integer
|
||||||
format, (({Float})) for float format.
|
format, (({Float})) for float format.
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s| eval(s) if s}
|
accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: OptionParser::DecimalInteger
|
: OptionParser::DecimalInteger
|
||||||
Decimal integer format, to be converted to (({Integer})).
|
Decimal integer format, to be converted to (({Integer})).
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
DecimalInteger = /\A[-+]?#{decimal}/io
|
DecimalInteger = /\A[-+]?#{decimal}/io
|
||||||
accept(DecimalInteger) {|s| s.to_i if s}
|
accept(DecimalInteger) {|s,| s.to_i if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: OptionParser::OctalInteger
|
: OptionParser::OctalInteger
|
||||||
|
@ -1376,7 +1375,7 @@ Default options, which never appear in option summary.
|
||||||
to (({Integer})).
|
to (({Integer})).
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io
|
OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io
|
||||||
accept(OctalInteger) {|s| s.oct if s}
|
accept(OctalInteger) {|s,| s.oct if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: OptionParser::DecimalNumeric
|
: OptionParser::DecimalNumeric
|
||||||
|
@ -1384,7 +1383,7 @@ Default options, which never appear in option summary.
|
||||||
(({Integer})) for integer format, (({Float})) for float format.
|
(({Integer})) for integer format, (({Float})) for float format.
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
DecimalNumeric = floatpat # decimal integer is allowed as float also.
|
DecimalNumeric = floatpat # decimal integer is allowed as float also.
|
||||||
accept(DecimalNumeric) {|s| eval(s) if s}
|
accept(DecimalNumeric) {|s,| eval(s) if s}
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
: TrueClass
|
: TrueClass
|
||||||
|
@ -1405,7 +1404,7 @@ Default options, which never appear in option summary.
|
||||||
: Array
|
: Array
|
||||||
List of strings separated by ","
|
List of strings separated by ","
|
||||||
=end #'#"#`#
|
=end #'#"#`#
|
||||||
accept(Array) do |s|
|
accept(Array) do |s,|
|
||||||
if s
|
if s
|
||||||
s = s.split(',').collect {|s| s unless s.empty?}
|
s = s.split(',').collect {|s| s unless s.empty?}
|
||||||
end
|
end
|
||||||
|
|
17
lib/optparse/date.rb
Normal file
17
lib/optparse/date.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'optparse'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
|
OptionParser.accept(DateTime) do |s,|
|
||||||
|
begin
|
||||||
|
DateTime.parse(s) if s
|
||||||
|
rescue ArgumentError
|
||||||
|
raise OptionParser::InvalidArgument, s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
OptionParser.accept(Date) do |s,|
|
||||||
|
begin
|
||||||
|
DateTime.parse(s) if s
|
||||||
|
rescue ArgumentError
|
||||||
|
raise OptionParser::InvalidArgument, s
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,4 +3,4 @@
|
||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
OptionParser.accept(Shellwords) {|s| Shellwords.shellwords(s)}
|
OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'time'
|
require 'time'
|
||||||
|
|
||||||
OptionParser.accept(Time) do |s|
|
OptionParser.accept(Time) do |s,|
|
||||||
begin
|
begin
|
||||||
(Time.httpdate(s) rescue Time.parse(s)) if s
|
(Time.httpdate(s) rescue Time.parse(s)) if s
|
||||||
rescue
|
rescue
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
OptionParser.accept(URI) {|s| URI.parse(s) if s}
|
OptionParser.accept(URI) {|s,| URI.parse(s) if s}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue