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
- #confirm!(msg) ⇒ Object
- #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
#confirm!(msg) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple/cli/helpers.rb', line 21 def confirm!(msg) STDERR.puts <<~MSG #{msg} Press return to continue, ^C to cancel... MSG STDIN.gets rescue Interrupt logger.error "Cancelled by user" exit 1 end |
#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
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/simple/cli/helpers.rb', line 45 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
41 42 43 |
# File 'lib/simple/cli/helpers.rb', line 41 def ssh!(target, command, user: nil) sys! "#{ssh_command(target, user: user)} #{command}" end |
#ssh_command(host, user: nil) ⇒ Object
36 37 38 39 |
# File 'lib/simple/cli/helpers.rb', line 36 def ssh_command(host, user: nil) host = "#{user}@#{host}" if user "#{SSH} #{host}" end |