Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6106

Show
Ignore:
Timestamp:
02/04/07 02:03:56 (3 years ago)
Author:
minam
Message:

Add :env option to 'run' (and friends) so that you can specify environment variables to be injected into the new process' environment (closes #7223)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/CHANGELOG

    r6105 r6106  
     1*SVN* 
     2 
     3* Add :env option to 'run' (and friends) so that you can specify environment variables to be injected into the new process' environment [Mathieu Lajugie] 
     4 
     5 
    16*1.4.0* (February 3, 2007) 
    27 
     
    2530* Fix off-by-one bug in show_tasks width-computation [NeilW] 
    2631 
     32 
    2733*1.3.1* (January 5, 2007) 
    2834 
    2935* Fix connection problems when using gateways [Ezra Zygmuntowicz] 
    3036 
     37 
    3138*1.3.0* (December 23, 2006) 
    3239 
     
    5865 
    5966* Added :as option to sudo, so you can specify who the command is executed as [Mark Imbriaco] 
     67 
    6068 
    6169*1.2.0* (September 14, 2006) 
  • tools/capistrano/lib/capistrano/command.rb

    r5775 r6106  
    1010    def initialize(servers, command, callback, options, actor) #:nodoc: 
    1111      @servers = servers 
    12       @command = command.strip.gsub(/\r?\n/, "\\\n") 
     12      @command = extract_environment(options) + command.strip.gsub(/\r?\n/, "\\\n") 
    1313      @callback = callback 
    1414      @options = options 
     
    9797        end 
    9898      end 
     99 
     100      # prepare a space-separated sequence of variables assignments 
     101      # intended to be prepended to a command, so the shell sets 
     102      # the environment before running the command. 
     103      # i.e.: options[:env] = {'PATH' => '/opt/ruby/bin:$PATH', 
     104      #                        'TEST' => '( "quoted" )'} 
     105      # extract_environment(options) returns: 
     106      # "TEST=(\ \"quoted\"\ ) PATH=/opt/ruby/bin:$PATH" 
     107      def extract_environment(options) 
     108        Array(options[:env]).inject("") do |string, (name, value)| 
     109          string << %|#{name}=#{value.gsub(/"/, "\\\"").gsub(/ /, "\\ ")} | 
     110        end 
     111      end 
    99112  end 
    100113end