lib/mdqt/cli/get.rb in mdqt-0.1.1 vs lib/mdqt/cli/get.rb in mdqt-0.2.0

- old
+ new

@@ -4,29 +4,61 @@ require 'mdqt/cli/base' class Get < Base - def run(args, options) + def run - client = MDQT::Client.new(base_url: options.service) + abort("Please specify --all if you wish to request all entities from #{options.service}") if args.empty? && !options.all - if args.empty? + results = get_results(args, options) - if options.all - results = [client.get_metadata("")] - else - abort("Please specify --all if you wish to request all entities from #{options.service}") - end + #results = MetadataValidator.validate_responses(results) if options.validate + #results = MetadataAggregator.aggregate_responses(results) if options.aggregate + + output_metadata(results, options) + + end + + def get_results(args, options) + + client = MDQT::Client.new( + options.service, + verbose: options.verbose, + cache_type: options.cache ? :file : :none + ) + + args.empty? ? [client.get_metadata("")] : args.collect {|entity_id| client.get_metadata(entity_id)} + + end + + def output_metadata(results, options) + case action(results, options) + when :save_files + output_files(results, options) + when :print_to_stdout + output_to_stdout(results, options) else - results = args.collect {|entity_id| client.get_metadata(entity_id)} + abort "Error - can't determine output type" end + end - results.each do |result| - puts result.body + def action(results, options) + case + when options.save + :save_files + else + :print_to_stdout end + end + def output_to_stdout(results, options) + results.each {|r| puts output(r)} + end + + def output_files(results, options) + abort "Unimplemented feature" end end end