From 71f8f164ca16f56581edbd7202d126ed05416d12 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 1 Feb 2023 14:04:51 +0100 Subject: [PATCH] Expose ssh_run --- lib/mrsk/cli/accessory.rb | 16 ++++++++++------ lib/mrsk/commands/accessory.rb | 4 ++++ lib/mrsk/commands/base.rb | 8 ++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/mrsk/cli/accessory.rb b/lib/mrsk/cli/accessory.rb index 8d5503e9..c334f281 100644 --- a/lib/mrsk/cli/accessory.rb +++ b/lib/mrsk/cli/accessory.rb @@ -87,20 +87,24 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base def exec(name, cmd) runner = \ case options[:method] - when "exec" then "exec" - when "run" then "run_exec" - when "ssh" then "exec_over_ssh" + when "exec" then "exec" + when "run" then "run_exec" + when "ssh_exec" then "exec_over_ssh" + when "ssh_run" then "run_over_ssh" else raise "Unknown method: #{options[:method]}" end.inquiry with_accessory(name) do |accessory| - if runner.exec_over_ssh? + if runner.exec_over_ssh? || runner.run_over_ssh? run_locally do info "Launching command on #{accessory.host}" - exec accessory.exec_over_ssh(cmd, host: accessory.host) + exec accessory.send(runner, cmd) end else - on(accessory.host) { puts capture_with_info(*accessory.send(runner, cmd)) } + on(accessory.host) do + info "Launching command on #{accessory.host}" + execute *accessory.send(runner, cmd) + end end end end diff --git a/lib/mrsk/commands/accessory.rb b/lib/mrsk/commands/accessory.rb index 629fe02b..43007929 100644 --- a/lib/mrsk/commands/accessory.rb +++ b/lib/mrsk/commands/accessory.rb @@ -63,6 +63,10 @@ class Mrsk::Commands::Accessory < Mrsk::Commands::Base *command end + def run_over_ssh(command) + super command, host: host + end + def exec_over_ssh(*command) run_over_ssh run_exec(*command, interactive: true).join(" "), host: host end diff --git a/lib/mrsk/commands/base.rb b/lib/mrsk/commands/base.rb index dc3924e0..49a8bf81 100644 --- a/lib/mrsk/commands/base.rb +++ b/lib/mrsk/commands/base.rb @@ -8,6 +8,10 @@ module Mrsk::Commands @config = config end + def run_over_ssh(command, host:) + "ssh -t #{config.ssh_user}@#{host} '#{command}'" + end + private def combine(*commands, by: "&&") commands @@ -27,9 +31,5 @@ module Mrsk::Commands def docker(*args) args.compact.unshift :docker end - - def run_over_ssh(command, host:) - "ssh -t #{config.ssh_user}@#{host} '#{command}'" - end end end