Class: DockerComposeDeploy::Util::Shell

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/docker_compose_deploy/util/shell.rb

Constant Summary

Constants included from Color

Color::CODES

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



8
9
10
11
# File 'lib/docker_compose_deploy/util/shell.rb', line 8

def initialize
  $stderr.sync = true
  $stdout.sync = true
end

Instance Method Details

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/docker_compose_deploy/util/shell.rb', line 58

def confirm?(question)
  warn "#{question} [Yn]"
  STDIN.gets.strip.downcase != 'n'
end

#exit(msg) ⇒ Object



41
42
43
44
# File 'lib/docker_compose_deploy/util/shell.rb', line 41

def exit(msg)
  warn(msg)
  Kernel.exit(1)
end

#notify(msg) ⇒ Object



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

def notify(msg)
  puts yellow(msg)
end

#puts(msg) ⇒ Object



37
38
39
# File 'lib/docker_compose_deploy/util/shell.rb', line 37

def puts(msg)
  Kernel.puts(msg)
end

#run(cmd) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/docker_compose_deploy/util/shell.rb', line 13

def run(cmd)
  puts blue(cmd)
  IO.popen(cmd) do |io|
    while (line = io.gets) do
      puts line
    end
  end
  $?
end

#run!(cmd) ⇒ Object



23
24
25
26
27
# File 'lib/docker_compose_deploy/util/shell.rb', line 23

def run!(cmd)
  if run(cmd) != 0
    exit("\nCommand failed:\n#{cmd}")
  end
end

#scp!(src, dest, opts = "") ⇒ Object



54
55
56
# File 'lib/docker_compose_deploy/util/shell.rb', line 54

def scp!(src, dest, opts="")
  run!("scp -F ~/.ssh/config -F ssh_config_overrides #{opts} #{src} #{dest} > /dev/tty")
end

#ssh(cmd) ⇒ Object



46
47
48
# File 'lib/docker_compose_deploy/util/shell.rb', line 46

def ssh(cmd)
  run(ssh_cmd(cmd))
end

#ssh!(cmd, opts = "") ⇒ Object



50
51
52
# File 'lib/docker_compose_deploy/util/shell.rb', line 50

def ssh!(cmd, opts="")
  run!(ssh_cmd(cmd, opts))
end

#ssh_cmd(cmd, opts) ⇒ Object



63
64
65
# File 'lib/docker_compose_deploy/util/shell.rb', line 63

def ssh_cmd(cmd, opts)
  "ssh -F ~/.ssh/config -F ssh_config_overrides #{opts} #{connection} '#{cmd}'"
end

#warn(msg) ⇒ Object



29
30
31
# File 'lib/docker_compose_deploy/util/shell.rb', line 29

def warn(msg)
  puts red(msg)
end