diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-20 22:45:06 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-09-20 22:45:06 +0000 |
commit | f6c46220c6607c583b8cc4c79c032261cfcb3da6 (patch) | |
tree | b88007385df04745a5f90d733a0a7da392aba08b /lib | |
parent | e7ad6ca4872bfa42c4475947da95992325f970c5 (diff) | |
download | ruby-f6c46220c6607c583b8cc4c79c032261cfcb3da6.tar.gz ruby-f6c46220c6607c583b8cc4c79c032261cfcb3da6.tar.xz ruby-f6c46220c6607c583b8cc4c79c032261cfcb3da6.zip |
* lib/optparse.rb (default_argv, Arguable#options): defaults strings
to be parsed to Arguable instance.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@9258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/optparse.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index aa2555f6f..8fc27f8cd 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 |