Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/kamal/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ def command
def subcommand
@kamal_subcommand ||= begin
invocation_class, invocation_commands = *first_invocation
invocation_commands[0] if invocation_class != Kamal::Cli::Main
if invocation_class != Kamal::Cli::Main
invocation_commands[0]
elsif subcommand_class = Kamal::Cli::Main.subcommand_classes[invocation_commands[0]]
# `kamal app boot` records Main's `app` first, then App's `boot`
instance_variable_get("@_invocations").fetch(subcommand_class, []).first
end
end
end

Expand Down
23 changes: 23 additions & 0 deletions test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ class CliAppTest < CliTestCase
end
end

test "boot through main names the subcommand to hooks and the output loggers" do
stub_running
Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)

hook_env = {}
SSHKit::Backend::Abstract.any_instance.stubs(:execute).with do |*args|
hook_env[args.first] = ENV.slice("KAMAL_COMMAND", "KAMAL_SUBCOMMAND") if args.first.to_s.start_with?(".kamal/hooks/")
true
end

modifications = []
subscriber = ActiveSupport::Notifications.subscribe("modify.kamal") do |*, payload|
modifications << payload.slice(:command, :subcommand)
end

stdouted { Kamal::Cli::Main.start([ "app", "boot", "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1" ]) }

assert_equal({ "KAMAL_COMMAND" => "app", "KAMAL_SUBCOMMAND" => "boot" }, hook_env[".kamal/hooks/pre-app-boot"])
assert_equal [ { command: "app", subcommand: "boot" } ], modifications
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end

test "boot will rename if same version is already running" do
Object.any_instance.stubs(:sleep)
run_command("details") # Preheat Kamal const
Expand Down
Loading