From 50b40771378fdefa7044a196c1df94844c18bb4c Mon Sep 17 00:00:00 2001 From: DavidMarchant Date: Wed, 27 Mar 2019 16:42:43 +0000 Subject: [PATCH 1/2] Never show data when specifying a map Instead always print all found assets' names --- lib/inventoryware/commands/shows/data.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/inventoryware/commands/shows/data.rb b/lib/inventoryware/commands/shows/data.rb index 6e94f17..5370c3f 100644 --- a/lib/inventoryware/commands/shows/data.rb +++ b/lib/inventoryware/commands/shows/data.rb @@ -74,11 +74,9 @@ def read_map(node, index) asset_paths << path if File.file?(path) end - if asset_paths.length < 1 + if asset_paths.empty? puts "No assets found under that index" - elsif asset_paths.length == 1 - output_file(asset_paths[0]) - elsif asset_paths.length > 1 + else puts asset_paths.map { |p| File.basename(p, File.extname(p)) } end end From 1eae1f0006eb6c42091ce48d92e4f392ed87f09c Mon Sep 17 00:00:00 2001 From: DavidMarchant Date: Wed, 27 Mar 2019 17:51:02 +0000 Subject: [PATCH 2/2] Return all asset names found anywhere in map line --- lib/inventoryware/commands/shows/data.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/inventoryware/commands/shows/data.rb b/lib/inventoryware/commands/shows/data.rb index 5370c3f..53d0fdc 100644 --- a/lib/inventoryware/commands/shows/data.rb +++ b/lib/inventoryware/commands/shows/data.rb @@ -66,18 +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.empty? + asset_names.select! { |name| line.include?(name) } + + if asset_names.empty? puts "No assets found under that index" else - puts asset_paths.map { |p| File.basename(p, File.extname(p)) } + puts asset_names end end end