require "yaml"
require "./command"
def load_yaml(path : String) : YAML::Any
YAML.parse(File.read(path))
end
def map_to_command(command_name : String, node : YAML::Any) : Command
image = node["image"].as_s
workdir = node["workdir"]?.try(&.as_s) || ""
shell = node["shell"]?.try(&.as_s) || "sh"
env = {} of String => String
if node["env"]?
node["env"].as_h.each do |k, v|
env[k.as_s] = v.as_s
end
end
commands = [] of String
if node["commands"]?
node["commands"].as_a.each do |c|
commands << c.as_s
end
end
cached = [] of String
if node["cached"]?
node["cached"].as_a.each do |c|
cached << c.as_s
end
end
artifacts_to_set = {} of String => String
if node["stash"]?
node["stash"].as_h.each do |k, v|
artifacts_to_set[k.as_s] = v.as_s
end
end
artifacts_to_get = {} of String => String
if node["unstash"]?
node["unstash"].as_h.each do |k, v|
artifacts_to_get[k.as_s] = v.as_s
end
end
Command.new(image,
command_name,
env,
commands,
cached,
shell,
workdir,
artifacts_to_set,
artifacts_to_get
)
end