33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/ssp/application/bags.rb', line 33
def upload(selected_bag = nil, selected_item = nil)
bags = if selected_bag
[data_bag_root.join(selected_bag)]
else
Pathname.glob(data_bag_root.join("*")).select {|p| p.directory?}
end
bags.each do |bag_path|
bag = bag_path.basename
say "Uploading #{shell.set_color(bag, :bold)}: "
knife_cmd "create #{bag} > /dev/null"
current_items = JSON.parse(knife_cmd("show #{bag}"))
items = if selected_bag and selected_item
[data_bag_root.join(selected_bag, "#{selected_item}.json")]
else
Pathname.glob(bag_path.join("*.json"))
end
items.each_with_index do |item, i|
key = item.basename.to_s.split(".").first
say "#{", " unless i == 0}#{key}", nil, false
command = current_items.include?(key) ? "edit" : "create"
knife_cmd "#{command} -e 'cat #{item} >' #{bag} #{key}"
end
puts
end
end
|