Method: Main::GetoptLong#set_options

Defined in:
lib/main/getoptlong.rb

#set_options(*arguments) ⇒ Object

Set options



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/main/getoptlong.rb', line 140

def set_options(*arguments)
  #
  # The method is failed if option processing has already started.
  #
  if @status != STATUS_YET
    raise RuntimeError, 
  "invoke set_options, but option processing has already started"
  end

  #
  # Clear tables of option names and argument flags.
  #
  @canonical_names.clear
  @argument_flags.clear

  arguments.each do |arg|
    #
    # Each argument must be an Array.
    #
    if !arg.is_a?(Array)
  raise ArgumentError, "the option list contains non-Array argument"
    end

    #
    # Find an argument flag and it set to `argument_flag'.
    #
    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
    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
    end
    raise ArgumentError, "no option name" if canonical_name == nil
  end
  return self
end