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

Skip shell option value if it's nil #774

Open
wants to merge 1 commit 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
5 changes: 3 additions & 2 deletions lib/kamal/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def argumentize(argument, attributes, sensitive: false)

# Returns a list of shell-dashed option arguments. If the value is true, it's treated like a value-less option.
def optionize(args, with: nil)
args = flatten_args(args).reject { |(_key, value)| value.nil? }
options = if with
flatten_args(args).collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
args.collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
else
flatten_args(args).collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
args.collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
end

options.flatten.compact
Expand Down
5 changes: 5 additions & 0 deletions test/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class UtilsTest < ActiveSupport::TestCase
Kamal::Utils.optionize({ foo: "bar", baz: "qux", quux: true }, with: "=")
end

test "optionize reject nil value" do
assert_equal [ "--foo", "\"bar\"", "--baz", "\"qux\"" ], \
Kamal::Utils.optionize({ foo: "bar", baz: "qux", quux: nil })
end

test "no redaction from #to_s" do
assert_equal "secret", Kamal::Utils.sensitive("secret").to_s
end
Expand Down