Class: Chemicalml::Cli::ValidateCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/chemicalml/cli/validate_command.rb

Overview

chemicalml validate <file> — auto-detect convention and print violations. With --json / -j, emits machine-readable JSON.

Instance Attribute Summary

Attributes inherited from Command

#logger

Instance Method Summary collapse

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from Chemicalml::Cli::Command

Instance Method Details

#run(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chemicalml/cli/validate_command.rb', line 9

def run(options)
  path = options[:file]
  unless path
    logger.error 'validate requires a <file> argument'
    return 2
  end

  logger.info "Validating #{path}" unless options[:json]
  doc = Chemicalml.parse(File.read(path), schema: :schema3)
  report = Chemicalml.validate(doc)

  if options[:json]
    puts json_report(report, path)
  elsif report.ok? && !report.has_warnings?
    logger.info "OK: #{path}"
  else
    logger.error report.summary
  end
  report.ok? ? 0 : 1
rescue ArgumentError, Lutaml::Model::InvalidFormatError => e
  logger.error "FAIL: #{e.message}"
  2
end