Class: Capistrano::Shell

Inherits:
Object
  • Object
show all
Includes:
Processable
Defined in:
lib/capistrano/shell.rb

Overview

The Capistrano::Shell class is the guts of the “shell” task. It implements an interactive REPL interface that users can employ to execute tasks and commands. It makes for a GREAT way to monitor systems, and perform quick maintenance on one or more machines.

Defined Under Namespace

Classes: ReadlineFallback

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Processable

#ensure_each_session, #process_iteration

Constructor Details

#initialize(config) ⇒ Shell

Instantiate a new shell



33
34
35
# File 'lib/capistrano/shell.rb', line 33

def initialize(config)
  @configuration = config
end

Instance Attribute Details

#configurationObject (readonly)

The configuration instance employed by this shell



25
26
27
# File 'lib/capistrano/shell.rb', line 25

def configuration
  @configuration
end

Class Method Details

.run(config) ⇒ Object

Instantiate a new shell and begin executing it immediately.



28
29
30
# File 'lib/capistrano/shell.rb', line 28

def self.run(config)
  new(config).run!
end

Instance Method Details

#read_and_executeObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/capistrano/shell.rb', line 57

def read_and_execute
  command = read_line

  case command
    when "?", "help" then help
    when "quit", "exit" then
      puts "exiting"
      return false
    when /^set -(\w)\s*(\S+)/
      set_option($1, $2)
    when /^set :(.*)\s+(.*)/
      configuration.set($1.to_sym, $2)
      puts "updated :#{$1} to #{$2}"
    when /^(?:(with|on)\s*(\S+))?\s*(\S.*)?/i
      process_command($1, $2, $3)
    else
      raise "eh?"
  end

  return true
end

#run!Object

Start the shell running. This method will block until the shell terminates.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capistrano/shell.rb', line 39

def run!
  setup

  puts <<-INTRO
====================================================================
Welcome to the interactive Capistrano shell! This is an experimental
feature, and is liable to change in future releases. Type 'help' for
a summary of how to use the shell.
--------------------------------------------------------------------
INTRO

  loop do
    break if !read_and_execute
  end

  @bgthread.kill
end