Method: RC::Interface#switch

Defined in:
lib/rc/interface.rb

#switch(command, switches = {}) ⇒ Object

Set enviroment variable(s) to command line switch value(s). This is a more general form of #profile_switch and will probably not get much use in this context.

Examples:

RC.switch('qed', '-p'=>'profile', '--profile'=>'profile')


233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/rc/interface.rb', line 233

def switch(command, switches={})
  return unless command.to_s == RC.current_command

  switches.each do |switch, envar|
    if index = ARGV.index(switch)
      ENV[envar] = ARGV[index+1]
    elsif arg = ARGV.find{ |a| a =~ /#{switch}=(.*?)/ }
      value = $1
      value = value[1..-2] if value.start_with?('"') && value.end_with?('"')
      value = value[1..-2] if value.start_with?("'") && value.end_with?("'")
      ENV[envar] = value
    end
  end
end