Module: Simple::CLI::Helpers
- Defined in:
- lib/simple/cli/helpers.rb
Overview
Helpers are mixed into all CLI modules. They implement the following methods, mostly to help with integrating external commands:
-
sys
-
sys!
-
sh!
-
die!
Defined Under Namespace
Classes: Command
Constant Summary collapse
- SSH =
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
Instance Method Summary collapse
- #die!(msg) ⇒ Object
- #logger ⇒ Object
- #sh!(cmd, *args) ⇒ Object
- #ssh!(target, command, user: nil) ⇒ Object
- #ssh_command(host, user: nil) ⇒ Object
- #sys(cmd, *args) ⇒ Object
- #sys!(cmd, *args) ⇒ Object
Instance Method Details
#die!(msg) ⇒ Object
12 13 14 15 |
# File 'lib/simple/cli/helpers.rb', line 12 def die!(msg) STDERR.puts msg exit 1 end |
#logger ⇒ Object
17 18 19 |
# File 'lib/simple/cli/helpers.rb', line 17 def logger ::Simple::CLI.logger end |
#sh!(cmd, *args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/simple/cli/helpers.rb', line 32 def sh!(cmd, *args) command = Command.new(cmd, *args) result = command.sh command.check_success! first_line, more = result.split("\n", 2) if more == "" first_line else result end end |
#ssh!(target, command, user: nil) ⇒ Object
28 29 30 |
# File 'lib/simple/cli/helpers.rb', line 28 def ssh!(target, command, user: nil) sys! "#{ssh_command(target, user: user)} #{command}" end |
#ssh_command(host, user: nil) ⇒ Object
23 24 25 26 |
# File 'lib/simple/cli/helpers.rb', line 23 def ssh_command(host, user: nil) host = "#{user}@#{host}" if user "#{SSH} #{host}" end |
#sys(cmd, *args) ⇒ Object
44 45 46 47 48 |
# File 'lib/simple/cli/helpers.rb', line 44 def sys(cmd, *args) command = Command.new(cmd, *args) command.run command.success? end |
#sys!(cmd, *args) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/simple/cli/helpers.rb', line 50 def sys!(cmd, *args) command = Command.new(cmd, *args) command.run command.check_success! true end |