Class: MDQT::CLI::Ls

Inherits:
Base
  • Object
show all
Defined in:
lib/mdqt/cli/ls.rb

Instance Method Summary collapse

Methods inherited from Base

#advise_on_xml_signing_support, #args, #btw, check_requirements, #colour_shell?, #explain, #extract_certificate_paths, #get_stdin, #halt!, #hey, #initialize, introduce, #options, #options=, #output, #pastel, #pipeable?, run, #say, #service_url, service_url, #yay

Constructor Details

This class inherits a constructor from MDQT::CLI::Base

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mdqt/cli/ls.rb', line 9

def run

  options.validate = true

  advise_on_xml_signing_support
  halt!("Cannot check a metadata file without XML support: please install additional gems") unless MDQT::Client.verification_available?

  client = MDQT::Client.new(
    options.service,
    verbose: options.verbose,
    explain: options.explain ? true : false,
  )

  results = []

  p_args = args.empty? ? Dir.glob("*.xml") : args

  p_args.each do |filename|

    file = client.(filename)

    halt!("Cannot access file #{filename}") unless file.readable?

    #halt!("File #{filename} is a metadata aggregate, cannot create entityID hashed link!") if file.aggregate?
    next if file.aggregate?
    halt!("XML validation failed for #{filename}:\n#{file.validation_error}") unless file.valid?

    halt!("Cannot find entityID for #{filename}") unless file.entity_id

    results << {id: file.entity_id, type: file.type, filename: file.basename}

  end

  results.sort_by { | r | [r[:id], r[:type]] }.each {|r| puts "#{r[:id]}, #{r[:type]}, #{r[:filename]}" }

end