Module: Capistrano::CLI::Execute

Included in:
Capistrano::CLI
Defined in:
lib/capistrano/cli/execute.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)

:nodoc:



6
7
8
# File 'lib/capistrano/cli/execute.rb', line 6

def self.included(base) #:nodoc:
  base.extend(ClassMethods)
end

Instance Method Details

- (Object) execute!

Using the options build when the command-line was parsed, instantiate a new Capistrano configuration, initialize it, and execute the requested actions.

Returns the Configuration instance used, if successful.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/capistrano/cli/execute.rb', line 23

def execute!
  config = instantiate_configuration(options)
  config.debug = options[:debug]
  config.dry_run = options[:dry_run]
  config.preserve_roles = options[:preserve_roles]
  config.logger.level = options[:verbose]

  set_pre_vars(config)
  load_recipes(config)

  config.trigger(:load)
  execute_requested_actions(config)
  config.trigger(:exit)

  config
rescue Exception => error
  handle_error(error)
end

- (Object) execute_requested_actions(config)



42
43
44
45
46
47
48
# File 'lib/capistrano/cli/execute.rb', line 42

def execute_requested_actions(config)
  Array(options[:vars]).each { |name, value| config.set(name, value) }

  Array(options[:actions]).each do |action|
    config.find_and_execute_task(action, :before => :start, :after => :finish)
  end
end

- (Object) handle_error(error)

:nodoc:



74
75
76
77
78
79
80
81
82
# File 'lib/capistrano/cli/execute.rb', line 74

def handle_error(error) #:nodoc:
  case error
  when Net::SSH::AuthenticationFailed
    abort "authentication failed for `#{error.message}'"
  when Capistrano::Error
    abort(error.message)
  else raise error
  end
end

- (Object) instantiate_configuration(options = {})

Primarily useful for testing, but subclasses of CLI could conceivably override this method to return a Configuration subclass or replacement.



70
71
72
# File 'lib/capistrano/cli/execute.rb', line 70

def instantiate_configuration(options={}) #:nodoc:
  Capistrano::Configuration.new(options)
end

- (Object) load_recipes(config)

:nodoc:



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/capistrano/cli/execute.rb', line 55

def load_recipes(config) #:nodoc:
  # load the standard recipe definition
  config.load "standard"

  # load systemwide config/recipe definition
  config.load(options[:sysconf]) if options[:sysconf] && File.file?(options[:sysconf])        

  # load user config/recipe definition
  config.load(options[:dotfile]) if options[:dotfile] && File.file?(options[:dotfile])

  Array(options[:recipes]).each { |recipe| config.load(recipe) }
end

- (Object) set_pre_vars(config)

:nodoc:



50
51
52
53
# File 'lib/capistrano/cli/execute.rb', line 50

def set_pre_vars(config) #:nodoc:
  config.set :password, options[:password]
  Array(options[:pre_vars]).each { |name, value| config.set(name, value) }
end