Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error to the user if the command parsed is blank #1405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def exec(*cmd)
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]
Expand Down
7 changes: 7 additions & 0 deletions test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down