Class: DockerComposeDeploy::Util::Shell
- Inherits:
-
Object
- Object
- DockerComposeDeploy::Util::Shell
- Includes:
- Color
- Defined in:
- lib/docker_compose_deploy/util/shell.rb
Constant Summary
Constants included from Color
Instance Method Summary collapse
- #confirm?(question) ⇒ Boolean
- #exit(msg) ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #notify(msg) ⇒ Object
- #puts(msg) ⇒ Object
- #run(cmd) ⇒ Object
- #run!(cmd) ⇒ Object
- #scp!(src, dest, opts = "") ⇒ Object
- #ssh(cmd) ⇒ Object
- #ssh!(cmd, opts = "") ⇒ Object
- #ssh_cmd(cmd, opts) ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize ⇒ Shell
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
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 |