Skip to content

Commit

Permalink
Merge pull request #547 from nickhammond/envify/trim-lines
Browse files Browse the repository at this point in the history
Enable trim mode with ERB
  • Loading branch information
djmb committed Oct 30, 2023
2 parents e3254b2 + 6c36c82 commit b732b2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kamal/cli/main.rb
Expand Up @@ -180,7 +180,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 unless options[:skip_push]
Expand Down
14 changes: 14 additions & 0 deletions test/cli/main_test.rb
Expand Up @@ -354,6 +354,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

0 comments on commit b732b2d

Please sign in to comment.