Class: Xapixctl::SyncCli
Defined Under Namespace
Classes: ResourcePath, SyncPath
Instance Method Summary
collapse
Methods inherited from BaseCli
exit_on_failure?, start
Instance Method Details
#diff(dir) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/xapixctl/sync_cli.rb', line 106
def diff(dir)
sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
sync_path.load_resource('project') do |desc|
desc['metadata']['id'] = prj_connection.project
res_details = prj_connection.project_resource
show_diff(desc, res_details)
end
sync_path.types_to_sync.each do |type|
res_path = sync_path.resource_path(type)
local_resource_ids = []
remote_resource_ids = prj_connection.resource_ids(type)
res_path.load_resources do |desc|
resource_id = desc['metadata']['id']
local_resource_ids << resource_id
if remote_resource_ids.include?(resource_id)
res_details = prj_connection.resource(type, desc['metadata']['id'])
show_diff(desc, res_details)
else
say "v #{type} #{resource_id}"
end
end
(remote_resource_ids - local_resource_ids).each do |resource_id|
say "^ #{type} #{resource_id}"
end
end
end
|
#from_dir(dir) ⇒ Object
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
|
# File 'lib/xapixctl/sync_cli.rb', line 58
def from_dir(dir)
sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
sync_path.load_resource('project') do |desc|
say "applying #{desc['kind']} #{desc.dig('metadata', 'id')} to #{prj_connection.project}"
desc['metadata']['id'] = prj_connection.project
prj_connection.organization.apply(desc)
end
outdated_resources = {}
sync_path.types_to_sync.each do |type|
res_path = sync_path.resource_path(type)
updated_resource_ids = []
res_path.load_resources do |desc|
say "applying #{desc['kind']} #{desc.dig('metadata', 'id')}"
updated_resource_ids += prj_connection.apply(desc)
end
outdated_resources[type] = prj_connection.resource_ids(type) - updated_resource_ids
end
outdated_resources.each do |type, resource_ids|
resource_ids.each do |resource_id|
say "removing #{type} #{resource_id}"
prj_connection.delete(type, resource_id)
end
end
end
|
#to_dir(dir) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/xapixctl/sync_cli.rb', line 27
def to_dir(dir)
sync_path = SyncPath.new(shell, dir, prj_connection.resource_types_for_export, excluded_types)
res_details = prj_connection.project_resource
sync_path.write_file(generate_readme(res_details), 'README.md')
sync_path.write_resource_yaml(res_details, 'project')
sync_path.types_to_sync.each do |type|
res_path = sync_path.resource_path(type)
prj_connection.resource_ids(type).each do |res_id|
res_details = prj_connection.resource(type, res_id)
res_path.write_resource_yaml(res_details, res_id)
end
res_path.remove_outdated_resources
end
sync_path.update_excluded_types_file
end
|