service: handle string run cmd
This was not handled at all during deserialization. The string argument gets turned into an array internally but we skip that to preserve all args in the @run_params variable. That means that we have to handle strings when deserializing too.
This commit is contained in:
parent
931327df1f
commit
39092fa629
@ -46,8 +46,11 @@ module Homebrew
|
|||||||
}
|
}
|
||||||
def run(command = nil, macos: nil, linux: nil)
|
def run(command = nil, macos: nil, linux: nil)
|
||||||
# Save parameters for serialization
|
# Save parameters for serialization
|
||||||
@run_params ||= command
|
if command
|
||||||
@run_params ||= { macos: macos, linux: linux }.compact
|
@run_params = command
|
||||||
|
elsif macos || linux
|
||||||
|
@run_params = { macos: macos, linux: linux }.compact
|
||||||
|
end
|
||||||
|
|
||||||
command ||= on_system_conditional(macos: macos, linux: linux)
|
command ||= on_system_conditional(macos: macos, linux: linux)
|
||||||
case T.unsafe(command)
|
case T.unsafe(command)
|
||||||
@ -551,15 +554,22 @@ module Homebrew
|
|||||||
hash = {}
|
hash = {}
|
||||||
hash[:run] =
|
hash[:run] =
|
||||||
case api_hash["run"]
|
case api_hash["run"]
|
||||||
when Hash
|
when String
|
||||||
api_hash["run"].to_h do |key, array|
|
replace_placeholders(api_hash["run"])
|
||||||
[
|
|
||||||
key.to_sym,
|
|
||||||
array.map(&method(:replace_placeholders)),
|
|
||||||
]
|
|
||||||
end
|
|
||||||
when Array
|
when Array
|
||||||
api_hash["run"].map(&method(:replace_placeholders))
|
api_hash["run"].map(&method(:replace_placeholders))
|
||||||
|
when Hash
|
||||||
|
api_hash["run"].to_h do |key, elem|
|
||||||
|
run_cmd = if elem.is_a?(Array)
|
||||||
|
elem.map(&method(:replace_placeholders))
|
||||||
|
else
|
||||||
|
replace_placeholders(elem)
|
||||||
|
end
|
||||||
|
|
||||||
|
[key.to_sym, run_cmd]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Unexepected run command: #{api_hash["run"]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
hash[:keep_alive] = api_hash["keep_alive"].transform_keys(&:to_sym) if api_hash.key?("keep_alive")
|
hash[:keep_alive] = api_hash["keep_alive"].transform_keys(&:to_sym) if api_hash.key?("keep_alive")
|
||||||
|
|||||||
@ -975,5 +975,37 @@ describe Homebrew::Service do
|
|||||||
it "replaces placeholders with local paths" do
|
it "replaces placeholders with local paths" do
|
||||||
expect(described_class.deserialize(serialized_hash)).to eq(deserialized_hash)
|
expect(described_class.deserialize(serialized_hash)).to eq(deserialized_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "run command" do
|
||||||
|
it "handles String argument correctly" do
|
||||||
|
expect(described_class.deserialize({
|
||||||
|
"run" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd",
|
||||||
|
})).to eq({
|
||||||
|
run: "#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles Array argument correctly" do
|
||||||
|
expect(described_class.deserialize({
|
||||||
|
"run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"],
|
||||||
|
})).to eq({
|
||||||
|
run: ["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "--option"],
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles Hash argument correctly" do
|
||||||
|
expect(described_class.deserialize({
|
||||||
|
"run" => {
|
||||||
|
"linux" => "$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd",
|
||||||
|
"macos" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "--option"],
|
||||||
|
},
|
||||||
|
})).to eq({
|
||||||
|
run: {
|
||||||
|
linux: "#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd",
|
||||||
|
macos: ["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "--option"],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user