Skip to content

Commit

Permalink
Make --detach incompatible with reuse or interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
aliismayilov committed Oct 23, 2024
1 parent 3af89f9 commit 6a21493
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/kamal/cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def details
option :env, aliases: "-e", type: :hash, desc: "Set environment variables for the command"
option :detach, type: :boolean, default: false, desc: "Execute command in a detached container"
def exec(*cmd)
if (incompatible_options = [ :interactive, :reuse ].select { |key| options[:detach] && options[key] }.presence)
raise ArgumentError, "Detach is not compatible with #{incompatible_options.join(" or ")}"
end

cmd = Kamal::Utils.join_commands(cmd)
env = options[:env]
detach = options[:detach]
Expand Down
20 changes: 19 additions & 1 deletion test/cli/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,25 @@ class CliAppTest < CliTestCase

test "exec detach" do
run_command("exec", "--detach", "ruby -v").tap do |output|
assert_match "docker run --detach --rm --env-file .kamal/env/roles/app-web.env dhh/app:latest ruby -v", output
assert_match "docker run --detach --rm --network kamal --env-file .kamal/apps/app/env/roles/web.env dhh/app:latest ruby -v", output
end
end

test "exec detach with reuse" do
assert_raises(ArgumentError, "Detach is not compatible with reuse") do
run_command("exec", "--detach", "--reuse", "ruby -v")
end
end

test "exec detach with interactive" do
assert_raises(ArgumentError, "Detach is not compatible with interactive") do
run_command("exec", "--interactive", "--detach", "ruby -v")
end
end

test "exec detach with interactive and reuse" do
assert_raises(ArgumentError, "Detach is not compatible with interactive or reuse") do
run_command("exec", "--interactive", "--detach", "--reuse", "ruby -v")
end
end

Expand Down

0 comments on commit 6a21493

Please sign in to comment.