Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/list map assets #123

Merged
merged 2 commits into from
Apr 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/inventoryware/commands/shows/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,17 @@ def read_map(node, index)
end

line = node.data['mutable']['map'][index]
#split on whitespace, commas and equals
words = line.split(/[\s,=]/)
asset_paths = []
words.each do |word|
path = File.join(Config.yaml_dir, "#{word}.yaml")
asset_paths << path if File.file?(path)

asset_names = Dir[File.join(Config.yaml_dir, '*')].map do |p|
p = File.basename(p, File.extname(p))
end

if asset_paths.length < 1
asset_names.select! { |name| line.include?(name) }

if asset_names.empty?
puts "No assets found under that index"
elsif asset_paths.length == 1
output_file(asset_paths[0])
elsif asset_paths.length > 1
puts asset_paths.map { |p| File.basename(p, File.extname(p)) }
else
puts asset_names
end
end
end
Expand Down