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

Enable trim mode with ERB #547

Merged
merged 1 commit into from Oct 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kamal/cli/main.rb
Expand Up @@ -179,7 +179,7 @@ def envify
env_path = ".env"
end

File.write(env_path, ERB.new(File.read(env_template_path)).result, perm: 0600)
File.write(env_path, ERB.new(File.read(env_template_path), trim_mode: "-").result, perm: 0600)

load_envs # reload new file
invoke "kamal:cli:env:push", options
Expand Down
14 changes: 14 additions & 0 deletions test/cli/main_test.rb
Expand Up @@ -346,6 +346,20 @@ class CliMainTest < CliTestCase
run_command("envify")
end

test "envify with blank line trimming" do
file = <<~EOF
HELLO=<%= 'world' %>
<% if true -%>
KEY=value
<% end -%>
EOF

File.expects(:read).with(".env.erb").returns(file.strip)
File.expects(:write).with(".env", "HELLO=world\nKEY=value\n", perm: 0600)

run_command("envify")
end

test "envify with destination" do
File.expects(:read).with(".env.world.erb").returns("HELLO=<%= 'world' %>")
File.expects(:write).with(".env.world", "HELLO=world", perm: 0600)
Expand Down