From 91259720b20cc299e56ccc1a76d1e01ae7275c87 Mon Sep 17 00:00:00 2001 From: Michael Weiner Date: Fri, 7 Feb 2025 20:13:18 -0600 Subject: [PATCH 1/3] Fail kamal app exec without a CMD --- lib/kamal/cli/app.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb index 553ccbb2..5d81c9a4 100644 --- a/lib/kamal/cli/app.rb +++ b/lib/kamal/cli/app.rb @@ -108,6 +108,10 @@ class Kamal::Cli::App < Kamal::Cli::Base raise ArgumentError, "Detach is not compatible with #{incompatible_options.join(" or ")}" end + if cmd.empty? + raise ArgumentError, "No command provided. You must specify a command to execute." + end + cmd = Kamal::Utils.join_commands(cmd) env = options[:env] detach = options[:detach] From 53778712787446262ca85ac875ef20f272430e48 Mon Sep 17 00:00:00 2001 From: Michael Weiner Date: Sat, 8 Feb 2025 13:09:57 -0600 Subject: [PATCH 2/3] Add UT for missing command --- test/cli/app_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 19190032..21a6c3f0 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -274,6 +274,13 @@ class CliAppTest < CliTestCase end end + test "exec without command fails" do + error = assert_raises(ArgumentError, "Exec requires a command to be specified") do + run_command("exec") + end + assert_equal 'No command provided. You must specify a command to execute.', error.message + end + test "exec separate arguments" do run_command("exec", "ruby", " -v").tap do |output| assert_match "docker run --rm --network kamal --env-file .kamal/apps/app/env/roles/web.env --log-opt max-size=\"10m\" dhh/app:latest ruby -v", output From 5e87b6d58e4cc859e6889ce82b3730377ef463ef Mon Sep 17 00:00:00 2001 From: Michael Weiner Date: Tue, 4 Mar 2025 06:32:08 -0600 Subject: [PATCH 3/3] Use double-quotes on UT --- test/cli/app_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 21a6c3f0..dab45f1b 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -278,7 +278,7 @@ class CliAppTest < CliTestCase error = assert_raises(ArgumentError, "Exec requires a command to be specified") do run_command("exec") end - assert_equal 'No command provided. You must specify a command to execute.', error.message + assert_equal "No command provided. You must specify a command to execute.", error.message end test "exec separate arguments" do