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

.included(base) ⇒ Object

:nodoc:



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

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

Instance Method Details

#execute!Object

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
# File 'lib/capistrano/cli/execute.rb', line 23

def execute!
  config = instantiate_configuration
  config.debug = options[:debug]
  config.dry_run = options[:dry_run]
  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

#execute_requested_actions(config) ⇒ Object



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

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

#handle_error(error) ⇒ Object

:nodoc:



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

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

#instantiate_configurationObject

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



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

def instantiate_configuration #:nodoc:
  Capistrano::Configuration.new
end

#load_recipes(config) ⇒ Object

:nodoc:



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

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

#set_pre_vars(config) ⇒ Object

:nodoc:



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

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