35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/locd/cli/command/project.rb', line 35
def load
file_path = options[:file].to_pn.expand_path
unless file_path.file?
raise "Definition file not found at `#{ file_path }`"
end
defs = YAML.load( file_path.read ).with_indifferent_access
t.hash_(
keys: t.in(%w{agents sites jobs}),
).check! defs
{
agents: Locd::Agent,
sites: Locd::Agent::Site,
jobs: Locd::Agent::Job,
}.each do |key, agent_class|
if defs.key? key
logger.info "Adding or updating #{ key }..."
defs[key].each do |label, values|
logger.info payload: {
values: values,
options: values.to_options,
}
method, agent = agent_class.add_or_update \
label: label,
**values.
map { |key, value|
key = key.gsub '-', '_'
if key == 'cmd_template'
value = value.squish
end
[ key, value ]
}.
to_h.
to_options
action = t.match method,
:add, 'added',
:update, 'updated'
logger.info "Agent `#{ label }` #{ action }"
end
end
end
end
|