summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-20 22:45:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-20 22:45:06 +0000
commit3f0e6bb6d2e126e4b4491285d9d02c31a01a8f07 (patch)
treeb88007385df04745a5f90d733a0a7da392aba08b
parent4b735fb95cc5feb0bbc088add04d69c907218390 (diff)
* lib/optparse.rb (default_argv, Arguable#options): defaults strings
to be parsed to Arguable instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/optparse.rb12
2 files changed, 14 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index c8df1e1..ad973af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Sep 21 07:43:58 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (default_argv, Arguable#options): defaults strings
+ to be parsed to Arguable instance.
+
Wed Sep 21 02:44:09 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (path_check_0): disallow sticky world writable directory
diff --git a/lib/optparse.rb b/lib/optparse.rb
index aa2555f..8fc27f8 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -810,6 +810,7 @@ class OptionParser
@banner = banner
@summary_width = width
@summary_indent = indent
+ @default_argv = ARGV
add_officious
yield self if block_given?
end
@@ -885,9 +886,13 @@ class OptionParser
--- OptionParser#program_name=(name)
Program name to be emitted in error message and default banner,
defaulted to (({$0})).
+--- OptionParser#default_argv
+--- OptionParser#default_argv=(argv)
+ Strings to be parsed in default.
=end #'#"#`#
attr_writer :banner, :program_name
attr_accessor :summary_width, :summary_indent
+ attr_accessor :default_argv
def banner
@banner ||= "Usage: #{program_name} [options]"
@@ -1260,7 +1265,7 @@ class OptionParser
order!(argv, &block)
end
- def order!(argv = ARGV, &nonopt)
+ def order!(argv = default_argv, &nonopt)
opt, arg, sw, val, rest = nil
nonopt ||= proc {|arg| throw :terminate, arg}
argv.unshift(arg) if arg = catch(:terminate) {
@@ -1340,7 +1345,7 @@ class OptionParser
permute!(argv)
end
- def permute!(argv = ARGV)
+ def permute!(argv = default_argv)
nonopts = []
arg = nil
order!(argv) {|arg| nonopts << arg}
@@ -1366,7 +1371,7 @@ class OptionParser
parse!(argv)
end
- def parse!(argv = ARGV)
+ def parse!(argv = default_argv)
if ENV.include?('POSIXLY_CORRECT')
order!(argv)
else
@@ -1760,6 +1765,7 @@ Extends command line arguments array to parse itself.
=end #'#"#`#
def options
@optparse ||= OptionParser.new
+ @optparse.default_argv = self
block_given? or return @optparse
begin
yield @optparse