summaryrefslogtreecommitdiff
path: root/lib/getoptlong.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-18 21:19:18 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-18 21:19:18 +0000
commit7bbf2f308580f468802cd7d32c94fce1b9f1779e (patch)
tree0a680f59e70a78d60e776d7b763e618fb2fec624 /lib/getoptlong.rb
parent34276148c4450faa77bb298cfbe005f7c263f802 (diff)
* lib: Convert tabs to spaces for ruby files per
http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto#coding-style Patch by Steve Klabnik [Ruby 1.9 - Bug #4730] Patch by Jason Dew [Ruby 1.9 - Feature #4718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/getoptlong.rb')
-rw-r--r--lib/getoptlong.rb214
1 files changed, 107 insertions, 107 deletions
diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb
index 7bd9ee55cc..30412a94c3 100644
--- a/lib/getoptlong.rb
+++ b/lib/getoptlong.rb
@@ -241,7 +241,7 @@ class GetoptLong
if @status != STATUS_YET
set_error(ArgumentError, "argument error")
raise RuntimeError,
- "invoke ordering=, but option processing has already started"
+ "invoke ordering=, but option processing has already started"
end
#
@@ -273,7 +273,7 @@ class GetoptLong
#
if @status != STATUS_YET
raise RuntimeError,
- "invoke set_options, but option processing has already started"
+ "invoke set_options, but option processing has already started"
end
#
@@ -284,7 +284,7 @@ class GetoptLong
arguments.each do |arg|
if !arg.is_a?(Array)
- raise ArgumentError, "the option list contains non-Array argument"
+ raise ArgumentError, "the option list contains non-Array argument"
end
#
@@ -292,44 +292,44 @@ class GetoptLong
#
argument_flag = nil
arg.each do |i|
- if ARGUMENT_FLAGS.include?(i)
- if argument_flag != nil
- raise ArgumentError, "too many argument-flags"
- end
- argument_flag = i
- end
+ if ARGUMENT_FLAGS.include?(i)
+ if argument_flag != nil
+ raise ArgumentError, "too many argument-flags"
+ end
+ argument_flag = i
+ end
end
raise ArgumentError, "no argument-flag" if argument_flag == nil
canonical_name = nil
arg.each do |i|
- #
- # Check an option name.
- #
- next if i == argument_flag
- begin
- if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
- raise ArgumentError, "an invalid option `#{i}'"
- end
- if (@canonical_names.include?(i))
- raise ArgumentError, "option redefined `#{i}'"
- end
- rescue
- @canonical_names.clear
- @argument_flags.clear
- raise
- end
-
- #
- # Register the option (`i') to the `@canonical_names' and
- # `@canonical_names' Hashes.
- #
- if canonical_name == nil
- canonical_name = i
- end
- @canonical_names[i] = canonical_name
- @argument_flags[i] = argument_flag
+ #
+ # Check an option name.
+ #
+ next if i == argument_flag
+ begin
+ if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
+ raise ArgumentError, "an invalid option `#{i}'"
+ end
+ if (@canonical_names.include?(i))
+ raise ArgumentError, "option redefined `#{i}'"
+ end
+ rescue
+ @canonical_names.clear
+ @argument_flags.clear
+ raise
+ end
+
+ #
+ # Register the option (`i') to the `@canonical_names' and
+ # `@canonical_names' Hashes.
+ #
+ if canonical_name == nil
+ canonical_name = i
+ end
+ @canonical_names[i] = canonical_name
+ @argument_flags[i] = argument_flag
end
raise ArgumentError, "no option name" if canonical_name == nil
end
@@ -447,17 +447,17 @@ class GetoptLong
return nil
elsif @ordering == PERMUTE
while 0 < ARGV.length && ARGV[0] !~ /^-./
- @non_option_arguments.push(ARGV.shift)
+ @non_option_arguments.push(ARGV.shift)
end
if ARGV.length == 0
- terminate
- return nil
+ terminate
+ return nil
end
argument = ARGV.shift
elsif @ordering == REQUIRE_ORDER
if (ARGV[0] !~ /^-./)
- terminate
- return nil
+ terminate
+ return nil
end
argument = ARGV.shift
else
@@ -482,49 +482,49 @@ class GetoptLong
#
pattern = $1
if @canonical_names.include?(pattern)
- option_name = pattern
+ option_name = pattern
else
- #
- # The option `option_name' is not registered in `@canonical_names'.
- # It may be an abbreviated.
- #
- matches = []
- @canonical_names.each_key do |key|
- if key.index(pattern) == 0
- option_name = key
- matches << key
- end
- end
- if 2 <= matches.length
- set_error(AmbiguousOption, "option `#{argument}' is ambiguous between #{matches.join(', ')}")
- elsif matches.length == 0
- set_error(InvalidOption, "unrecognized option `#{argument}'")
- end
+ #
+ # The option `option_name' is not registered in `@canonical_names'.
+ # It may be an abbreviated.
+ #
+ matches = []
+ @canonical_names.each_key do |key|
+ if key.index(pattern) == 0
+ option_name = key
+ matches << key
+ end
+ end
+ if 2 <= matches.length
+ set_error(AmbiguousOption, "option `#{argument}' is ambiguous between #{matches.join(', ')}")
+ elsif matches.length == 0
+ set_error(InvalidOption, "unrecognized option `#{argument}'")
+ end
end
#
# Check an argument to the option.
#
if @argument_flags[option_name] == REQUIRED_ARGUMENT
- if argument =~ /=(.*)$/
- option_argument = $1
- elsif 0 < ARGV.length
- option_argument = ARGV.shift
- else
- set_error(MissingArgument,
- "option `#{argument}' requires an argument")
- end
+ if argument =~ /=(.*)$/
+ option_argument = $1
+ elsif 0 < ARGV.length
+ option_argument = ARGV.shift
+ else
+ set_error(MissingArgument,
+ "option `#{argument}' requires an argument")
+ end
elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
- if argument =~ /=(.*)$/
- option_argument = $1
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
- option_argument = ARGV.shift
- else
- option_argument = ''
- end
+ if argument =~ /=(.*)$/
+ option_argument = $1
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
+ option_argument = ARGV.shift
+ else
+ option_argument = ''
+ end
elsif argument =~ /=(.*)$/
- set_error(NeedlessArgument,
- "option `#{option_name}' doesn't allow an argument")
+ set_error(NeedlessArgument,
+ "option `#{option_name}' doesn't allow an argument")
end
elsif argument =~ /^(-(.))(.*)/
@@ -536,40 +536,40 @@ class GetoptLong
option_name, ch, @rest_singles = $1, $2, $3
if @canonical_names.include?(option_name)
- #
- # The option `option_name' is found in `@canonical_names'.
- # Check its argument.
- #
- if @argument_flags[option_name] == REQUIRED_ARGUMENT
- if 0 < @rest_singles.length
- option_argument = @rest_singles
- @rest_singles = ''
- elsif 0 < ARGV.length
- option_argument = ARGV.shift
- else
- # 1003.2 specifies the format of this message.
- set_error(MissingArgument, "option requires an argument -- #{ch}")
- end
- elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
- if 0 < @rest_singles.length
- option_argument = @rest_singles
- @rest_singles = ''
- elsif 0 < ARGV.length && ARGV[0] !~ /^-./
- option_argument = ARGV.shift
- else
- option_argument = ''
- end
- end
+ #
+ # The option `option_name' is found in `@canonical_names'.
+ # Check its argument.
+ #
+ if @argument_flags[option_name] == REQUIRED_ARGUMENT
+ if 0 < @rest_singles.length
+ option_argument = @rest_singles
+ @rest_singles = ''
+ elsif 0 < ARGV.length
+ option_argument = ARGV.shift
+ else
+ # 1003.2 specifies the format of this message.
+ set_error(MissingArgument, "option requires an argument -- #{ch}")
+ end
+ elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
+ if 0 < @rest_singles.length
+ option_argument = @rest_singles
+ @rest_singles = ''
+ elsif 0 < ARGV.length && ARGV[0] !~ /^-./
+ option_argument = ARGV.shift
+ else
+ option_argument = ''
+ end
+ end
else
- #
- # This is an invalid option.
- # 1003.2 specifies the format of this message.
- #
- if ENV.include?('POSIXLY_CORRECT')
- set_error(InvalidOption, "invalid option -- #{ch}")
- else
- set_error(InvalidOption, "invalid option -- #{ch}")
- end
+ #
+ # This is an invalid option.
+ # 1003.2 specifies the format of this message.
+ #
+ if ENV.include?('POSIXLY_CORRECT')
+ set_error(InvalidOption, "invalid option -- #{ch}")
+ else
+ set_error(InvalidOption, "invalid option -- #{ch}")
+ end
end
else
#