diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb index ed1870ba..da2db238 100644 --- a/lib/kamal/cli/app.rb +++ b/lib/kamal/cli/app.rb @@ -112,6 +112,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] diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index af673ce1..94742d34 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -312,6 +312,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