From cd668066ff6304eab4ad71de7a7537ee2c8b981f Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Tue, 25 Apr 2023 15:15:55 +0100 Subject: [PATCH] Get lock status by executing directly Getting the lock status with invoke passes through any options from the original command which will raise an exception if they are not also valid for the lock status command. Fixes https://github.com/mrsked/mrsk/issues/239 --- lib/mrsk/cli/base.rb | 2 +- test/cli/main_test.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/cli/base.rb b/lib/mrsk/cli/base.rb index f772b821..76f4f326 100644 --- a/lib/mrsk/cli/base.rb +++ b/lib/mrsk/cli/base.rb @@ -105,7 +105,7 @@ module Mrsk::Cli MRSK.holding_lock = true rescue SSHKit::Runner::ExecuteError => e if e.message =~ /cannot create directory/ - invoke "mrsk:cli:lock:status", [] + on(MRSK.primary_host) { execute *MRSK.lock.status } raise LockError, "Deploy lock found" else raise e diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 0af67f43..5cac1132 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -64,7 +64,8 @@ class CliMainTest < CliTestCase .with { |*arg| arg[0..1] == [:mkdir, :mrsk_lock] } .raises(RuntimeError, "mkdir: cannot create directory ‘mrsk_lock’: File exists") - Mrsk::Cli::Base.any_instance.expects(:invoke).with("mrsk:cli:lock:status", []) + SSHKit::Backend::Abstract.any_instance.expects(:execute) + .with(:stat, :mrsk_lock, ">", "/dev/null", "&&", :cat, "mrsk_lock/details", "|", :base64, "-d") assert_raises(Mrsk::Cli::LockError) do run_command("deploy")