Method: RC::Interface#profile_switch

Defined in:
lib/rc/interface.rb

#profile_switch(command, *switches) ⇒ Object

Set current profile via ARGV switch. This is done immediately, setting ‘ENV` to the switch value if this setup is for the current commandline tool. The reason it is done immediately, rather than assigning it in bootstrap, is b/c option parsers somtimes consume ARGV as they parse it, and by then it would too late.

Examples:

RC.profile_switch('qed', '-p', '--profile')


211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/rc/interface.rb', line 211

def profile_switch(command, *switches)
  return unless command.to_s == RC.current_command

  switches.each do |switch, envar|
    if index = ARGV.index(switch)
      self.current_profile = 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?("'")
      self.currrent_profile = value
    end
  end
end